POWER BI DAX : Complex two layered Average Calculation
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 towards compalince = 5 and weekly frequency Target = 1
so we have to consider reading towards copaliance as 1 for this record for higher aggregations ie when we consider more than 1 week .
so to achieve this we to effective value
[Readings Towards Compliance effective] = If([Readings Towards Compliance])>[Weekly Frequency Target],[Weekly Frequency Target],[Readings Towards Compliance]))
to get MAX of weekly frequency target in a week
WeeKFrequencyMeasure = MAXX(DISTINCT(View_Compliance[MonitoringKey]),MAX(View_Compliance[Week Frequency Target]))
To sum up all Max value from each week while aggregating more than a week level
[Weekly Frequeny Target Agg] = sumx(distinct('Date'[Week Ending]),SUMX(DISTINCT(View_Compliance[MonitoringKey]),[WeeKFrequencyMeasure]))
To sum up all reading towards compliance with effective value
[Reading Towards Compliance Agg] = SUMX(DISTINCT('Date'[Week Ending]),SUMX(DISTINCT(View_Compliance[MonitoringKey]),[Readings Towards Compliance effective]))
[Complaince % ]= [Reading Towards Compliance Agg]/[Weekly Frequeny Target Agg]
NOTE : complaince % works fine at both the layers
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 towards compalince = 5 and weekly frequency Target = 1
so we have to consider reading towards copaliance as 1 for this record for higher aggregations ie when we consider more than 1 week .
so to achieve this we to effective value
[Readings Towards Compliance effective] = If([Readings Towards Compliance])>[Weekly Frequency Target],[Weekly Frequency Target],[Readings Towards Compliance]))
to get MAX of weekly frequency target in a week
WeeKFrequencyMeasure = MAXX(DISTINCT(View_Compliance[MonitoringKey]),MAX(View_Compliance[Week Frequency Target]))
To sum up all Max value from each week while aggregating more than a week level
[Weekly Frequeny Target Agg] = sumx(distinct('Date'[Week Ending]),SUMX(DISTINCT(View_Compliance[MonitoringKey]),[WeeKFrequencyMeasure]))
To sum up all reading towards compliance with effective value
[Reading Towards Compliance Agg] = SUMX(DISTINCT('Date'[Week Ending]),SUMX(DISTINCT(View_Compliance[MonitoringKey]),[Readings Towards Compliance effective]))
[Complaince % ]= [Reading Towards Compliance Agg]/[Weekly Frequeny Target Agg]
NOTE : complaince % works fine at both the layers
• Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating. Power Bi Online Training Hyderabad
ReplyDeleteThe CALCULATE function in DAX is the magic key for many calculations we can do in DAX. Calculate dax function enables you to work in different ways using a similar insight without having to rewrite formulas or calculations. To know more feel free to contact us.
ReplyDelete