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.
Hi,
I'm looking to two sale previous year measures in the same column. Sales for the full year and sales to the same day last year. Normally I wouldn't have the need to include both in a table, and would have two cards using the following simple DAX.
Hello,
First of all you should create a Date Dimension and link that to your table that has the Sales. So based on the PoC, that i have done for your question i have created two tables:
1. The Date Dimension
2. The Sales Table
In the data model view i have conneted the date dimension to the Sales table. (key is Date)
And in the report view i have added a Slicer for date and a table having 3 columns
1. Sum of Sales (the sum of sales for the date range selected)
2. SalesSamePeriodLY
SalesSamePeriodLY =
CALCULATE(
SUM(sales_powerbi_answers[Sales]),
SAMEPERIODLASTYEAR('Date'[Date])
)
which according to the date data and if the dates available SAMEPERIODLASTYEAR(), calculates the exactly same period but for the previous year, based on the selected data.
3. SalesFullLastYear
SalesFullLastYear =
var _Current_Year = CALCULATE(MAX('Date'[Date]),ALLSELECTED())
var _Previous_Year = YEAR(_Current_Year) - 1
RETURN
CALCULATE(
SUM(sales_powerbi_answers[Sales]),
YEAR('Date'[Date]) = _Previous_Year
)
which calculates the max available date and based on that calculates the sum of sales for the previous year.
The result (as you can see the Full Last Year remains constant and the Same Period Last Year changes based on the range selected)
i hope this helps.
Thanks for this - appreciated, but would not provide a solution in my case as we have ascertained that I need to be able to incorporate the start of the Fiscal Year (01/05) into my solution somewhere. I'm fine with my SamePeriodLastYear measure which reflects yours, but ideally need to be able to adapt the DAX Johnt75 had suggested before to accept the start of the FY - have been trying various different ways with no success. Thanks again.
If you have values from your date table in the visual then you don't need the bit about today, you could just use
Sales Same Period Last Year =
CALCULATE ( [Amount Measure], DATEADD ( DATESYTD ( 'Date'[Date] ), -1, YEAR ) )
Thanks again @johnt75
Gave that a go also but still coming back with unexpected results...
Test is the amended DAX you suggested so coming back with a lower figure than previously, but the card that you see overlayed shows the sales same period last year to the day figure which is zero.
Which columns from the date table are you using in the visual? I would expect a YTD figure to grow over time.
You could add a measure like
Num Visible Days =
COUNTROWS ( DATEADD ( DATESYTD ( 'Date'[Date] ), -1, YEAR ) )
to show whether the correct dates are being calculated.
Great suggestion and it flags what the issue is here - it's counting back to the start of the calendar year as opposed to the Financial Year that I'm working on! My FY is 01/05/ - 30/04 and that is set up using a calc column...
Hi @johnt75
Thanks for the suggestion and gave that a go, but definitely some unexpected results in there...
DTS SAles PY (FullYear) is essentially the SamePeriodLast Year Measure without the calculated column visual level filter applied and I know those figures are good. TEST column in your suggested Measure - you will see the second line down that it calculates Sales approx 18k above the whole of the previous year.
Try
Sales Same Period Last Year =
CALCULATE (
[Amount Measure],
CALCULATETABLE (
DATEADD ( DATESYTD ( 'Date'[Date] ), -1, YEAR ),
TREATAS ( { TODAY () }, 'Date'[Date] )
)
)
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 |
---|---|
47 | |
26 | |
19 | |
15 | |
10 |
User | Count |
---|---|
57 | |
50 | |
44 | |
21 | |
19 |