Posts

Showing posts with the label DAX

POWER BI DAX : Complex two layered Average Calculation

Image
Hi All we got a scenario where we have a table with daily granularity and we need to aggregate weekly taking denominator column MAX and numerator column relative SUM and create ratio (percentage). For aggregation above week we need to take SUM of denominator .so layer 1 within week and layer 2 above week format and we need to take averages for the percentage on both layers if you see the image , we need to represent data on weekly basis and  issue here is  [weekly freqency target] is present in all the records of the week in a table, in  above report each row represents weeks data ,so we have to take only one value from those 7 days , so here we need to take Max of that value Compliance %  = Reading towards Complaince/ weekly frequency target Another challange here is Reading towards complaince  may be greater than weekly frequency in those cases we need to consider only 100 % example               Reading toward...

DAX : Cummulative Sum including Missing dates in Fact

Hi All we got a situation where we need to calculate daily budget , even  if fact table missing some dates we need to calculate for dates Cumulative Budget = VAR RowDate = DateTime[Date] RETURN     CALCULATE (         SUM ( DateTime[Budget]),         FILTER (             DateTime,             DateTime[Date] <= RowDate   && YEAR ( DateTime[Date] ) = YEAR ( RowDate )  && month ( DateTime[Date] ) = MONTH( ( RowDate )

PowerBI : How to Calculate number of WorkingDays between 2 given dates

Image
Here i am going to explain how to calculate number of working dates between to given dates. In my approach i am taking a table called Holidays which contains holidays as shown below Once you have this table , we need to use this table in our Datetime table to calculate IsworkingDay column. Now give the relationship between Datetime and Holidays tables as shown below DAX :  IsWorkingDay = IF (NOT(DateTime[Day of Week]= "Saturday" || (DateTime[Day of Week]= "Sunday")) && COUNTX(RELATEDTABLE(Holidays),2)<1,1,0) Now you can create calculated column or measure  Total Working Days Column =  SUMX (     FILTER (         'Datetime',         'Datetime'[Date] >= Tasks[Input Start Date]             && 'Datetime'[Date] <= Tasks[Input End Date]     ),     'Datetime'[IsWorkingDay] ) Total Working Days Measure =...