Forum Discussion
How to sum up data having same label (DAX Query)?
Umm, no.
I'll provide a snapshot and try to explain my problem in a better way.
Matrix in Power bi
So, as you can see every row in the matrix has an associated label. Which means in the dataset, for instance - for week : 2021-W23 (which is a text, not a date format) all the thousands of rows having visits data have a label of -31. The visits of the weeks are naturally summed up when I represent them in a matrix. Mind you I have done some computation to represent the label in the manner otherwise it was also being summed up.
So all I want is the visits value of the previous row in every row. So for 2021-W23, the prev_week will be blank. For 2021-W24, the prev_week should have the visits value of 2021-W23 and so on.
Kindly help me out.
Hi,
Hope this code helps you to understand a potential solution using naturalinnerjoin. pls let me know if you have further questions.
- Anonymous5 years agoNot applicable
Nah, this isn't it.
Thanks for the effort though.
- stevedep5 years ago
Memorable Member
Perhaps this is what you are looking for:
DEFINE MEASURE 'Date'[Rank] = RANKX ( ALL ( 'Date'[Calendar Year Month] ), CALCULATE ( SUM ( Sales[Quantity] ) ),,,SKIP) MEASURE 'Date'[SalesPrevPeriod] = VAR _r = 'Date'[Rank] - 1 RETURN MAXX ( FILTER ( ADDCOLUMNS ( ALL ( 'Date'[Calendar Year Month] ), "sales", CALCULATE ( SUM ( Sales[Quantity] ) ), "rank", 'Date'[Rank] ), [rank] = _r ), [sales] ) EVALUATE ADDCOLUMNS ( VALUES ( 'Date'[Calendar Year Month] ), "sales", CALCULATE ( SUM ( Sales[Quantity] ) ), "t", [Rank], "salesprevperiod", [SalesPrevPeriod] ) ORDER BY [t]See it working here.
Hope it helps.
Kind regards,
Steve.
- Anonymous5 years agoNot applicable
Could you explain the code?
I am not able to understand it in this context