Forum Discussion
Per Unit Computation Dax
- Anonymous4 years ago
Hi icdns ,
I download you sample and have test. Firstly I suggest to to sort [Month] column by [MonthNo] column.
For reference: Sort one column by another column in Power BI Desktop
Then create a measure as below to achieve your goal.
Sales Percentage = VAR _SUMMARIZE = SUMMARIZE ( ALLSELECTED ( sampledata ), sampledata[Year], sampledata[Month], sampledata[City], "Sales", CALCULATE ( SUM ( sampledata[Sales] ) ) ) VAR _ADDMAX = ADDCOLUMNS ( _SUMMARIZE, "MaxSales", MAXX ( FILTER ( _SUMMARIZE, [City] = EARLIER ( [City] ) ), [Sales] ) ) VAR _Sales = CALCULATE ( SUM ( sampledata[Sales] ) ) VAR _MaxSales = MAXX ( FILTER ( _ADDMAX, [City] = MAX ( sampledata[City] ) ), [MaxSales] ) RETURN DIVIDE ( _Sales, _MaxSales )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi icdns ,
I download you sample and have test. Firstly I suggest to to sort [Month] column by [MonthNo] column.
For reference: Sort one column by another column in Power BI Desktop
Then create a measure as below to achieve your goal.
Sales Percentage =
VAR _SUMMARIZE =
SUMMARIZE (
ALLSELECTED ( sampledata ),
sampledata[Year],
sampledata[Month],
sampledata[City],
"Sales", CALCULATE ( SUM ( sampledata[Sales] ) )
)
VAR _ADDMAX =
ADDCOLUMNS (
_SUMMARIZE,
"MaxSales", MAXX ( FILTER ( _SUMMARIZE, [City] = EARLIER ( [City] ) ), [Sales] )
)
VAR _Sales =
CALCULATE ( SUM ( sampledata[Sales] ) )
VAR _MaxSales =
MAXX ( FILTER ( _ADDMAX, [City] = MAX ( sampledata[City] ) ), [MaxSales] )
RETURN
DIVIDE ( _Sales, _MaxSales )
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.