Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I am trying to compare sales of each store with last year based on the currently selected period. The issue here, there were no sales in this year and last year for certain days, What I am exactly looking for is to compare between dates that were available both in this year and last year.
I got the current year sales calculation working with the following formula but I cannot find a solution for the previous year sales total.
CY SALES = CALCULATE([Sales Amount], FILTER(CROSSJOIN(VALUES(DIM[STORE]),VALUES(CAL[DATE])), CALCULATE([Sales Amount],SAMEPERIODLASTYEAR(CAL[DATE]))>0 ) )
The amount for last year should be 261,057
https://1drv.ms/u/s!AmoScH5srsIYt0Fr8L-6r8HkFEI7
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Solved! Go to Solution.
Hi, this code should work. You can return CY, LY or delta (the number computed right now) by simply changing the RETURN part:
Diff = SUMX ( SUMMARIZE ( 'FACT', 'CAL'[DATE], DIM[STORE] ), VAR SalesCY = [CY Sales Amount] VAR SalesLY = CALCULATE ( [CY Sales Amount], SAMEPERIODLASTYEAR( CAL[DATE] ) ) RETURN IF ( AND ( SalesCY > 0, SalesLY > 0 ), SalesCY - SalesLY ) )
It is not going to be a top-performer in terms of speed, but good enough for small data volumes.
Have fun with DAX!
Alberto Ferrari
http://www.sqlbi.com
Firstly, I should say that It's my honor to have the question answered by Aberto Ferrari !
The solution worked perfectly,
I was overly focusing on time intelligence and failed to make use of SUMX and variables.
DAX is getting more interesting.
Thanks again!
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Hi, this code should work. You can return CY, LY or delta (the number computed right now) by simply changing the RETURN part:
Diff = SUMX ( SUMMARIZE ( 'FACT', 'CAL'[DATE], DIM[STORE] ), VAR SalesCY = [CY Sales Amount] VAR SalesLY = CALCULATE ( [CY Sales Amount], SAMEPERIODLASTYEAR( CAL[DATE] ) ) RETURN IF ( AND ( SalesCY > 0, SalesLY > 0 ), SalesCY - SalesLY ) )
It is not going to be a top-performer in terms of speed, but good enough for small data volumes.
Have fun with DAX!
Alberto Ferrari
http://www.sqlbi.com
Firstly, I should say that It's my honor to have the question answered by Aberto Ferrari !
The solution worked perfectly,
I was overly focusing on time intelligence and failed to make use of SUMX and variables.
DAX is getting more interesting.
Thanks again!
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
I am trying to compare sales of each store with last year based on the currently selected period. The issue here, there were no sales in this year and last year for certain days, What I am exactly looking for is to compare between dates that were available both in this year and last year.
I got the current year sales calculation working with the following formula but I cannot find a solution for the previous year sales total.
CY TEST = CALCULATE([Sales Amount], FILTER(CROSSJOIN(VALUES(DIM[STORE]),VALUES(CAL[DATE])),
CALCULATE([Sales Amount],SAMEPERIODLASTYEAR(CAL[DATE]))>0
) )
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
97 | |
96 | |
81 | |
74 | |
66 |
User | Count |
---|---|
129 | |
106 | |
106 | |
86 | |
72 |