Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
I am trying to display in a card the previous years total sales value, so as we are in 2022, I want to display 2021, and then next year I want it to display 2022 total sales.
In testing I have the below and this gives me the correct figures...
Total_Previous_Year_Spend =
CALCULATE(SUM('MDSL Output'[Net Amount]), Dates[Year]="2021")
but need something like the below so every new year it will automatically look at the previous year...
Solved! Go to Solution.
OK, Figures it out. Might not be the most elegant code, but it works...
OK, Figures it out. Might not be the most elegant code, but it works...
@StuartSmith , example with help from date table and time intelligence
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR('Date'[Date]))
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
//Only year vs Year, not a level below
This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))
Thanks and will take a look at your solutions shortly, but curious as to why the Var Total_Previous_Year_Spend2 doesnt work using the "Previous_Year" variable.
Would i need to convert the "Previous_Year" number into a string, so it works?
Var Total_Previous_Year_Spend2 = CALCULATE(SUM('MDSL Output'[Net Amount]), Dates[Year]=Previous_Year)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
User | Count |
---|---|
84 | |
69 | |
68 | |
39 | |
38 |