The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hello all,
I'm trying to create a measure which show the YTD for the same period in previous years.So far I've created a YTD measure for this year which is:YTD = TOTALYTD(SUM(Sheet1[Sales TY]),Dates[Date])*1000
I've also created a YTD for last year, which is: YTD -1 = CALCULATE([Total sales LY],DATESYTD(Dates[Date]))
I created a separate table for year and a "Is current year" measure in my date table which contains the value of 1 if the date is in 2021. Then I used this DAX to find the YTD for the years previous to the selected ones:
YTD All Years =VAR YearsBack = YEAR(TODAY()) - SELECTEDVALUE(Years[Year])RETURNCALCULATE([Totalt salg YTD],DATEADD(Dates[Date], -YearsBack, YEAR))
This was the result:
However, as you can see from the 2021 line, my data is updated once a month and only contains values from late 2018 until august this year. However the grap "thinks" that we're in December 31st, and so therefore doesn't show YTD from january until august, but from january until december. Any idea how to fix this?
This is the final date from the data set I imported. I have however created a separate data table called Dates which consists of dates until december 31st:
Also, even my YTD - 1 measure seems to be off, as it shows the entire sales value of 2020, and not january-august like my YTD for this year measure does. This is how it's looking in my dashboard:
And this is how the values are supposed to look:
Would appreciate any help!! Also, sorry if this was posted in the wrong section.
@Bobbys Try something like:
YTD -1 =
VAR __Max = MAX('Sheet1'[Date])
VAR __LY = DATE(YEAR(__Max)-1,MONTH(__Max),DAY(__Max))
RETURN
CALCULATE([Total value LY],DATESYTD(Dates[Date]),FILTER(Dates[Date]<__LY)*1000
if you don't want to monkey around with TI functions then you could have done this without TI functions or even a date table:
YTD =
VAR __Max = MAX('Sheet1'[Date])
VAR __Min = MINX(FILTER('Sheet1',YEAR([Date])=YEAR(__Max)),[Date])
RETURN
SUMX(FILTER('Sheet1',[Date]>=__Min && [Date]<=__Max),[Value])
YTD -1 =
VAR __Max = MAX('Sheet1'[Date])
VAR __Min = MINX(FILTER('Sheet1',YEAR([Date])=YEAR(__Max)),[Date])
VAR __LYMax = DATE(YEAR(__Max)-1,MONTH(__Max),DAY(__Max))
VAR __LYMin = DATE(YEAR(__Min)-1,MONTH(__Min),DAY(__Min))
RETURN
SUMX(FILTER('Sheet1',[Date]>=__LYMin && [Date]<=__LYMax),[Value])
Thank you @Greg_Deckler, and I'll make sure to keep that in mind. If there is a way to get the measures I want without creating a whole new table, I'm totally down for that. Now that I've already made my date table though, I'll try the formula you posted. I got a error when trying to implement it: https://gyazo.com/454e4d4674b588a07922fa2ed96a4a8d
The error says "Too few arguments were passed to the filter funtion".
@Bobbys You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000
Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...
If that's not helpful, Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
Hello @Greg_Deckler, thanks for the info.
Did however not find much help in those posts.
I'll try and explain my problem more clearly:
This is how my raw data looks.
Date (Year Week) | Product | Value | Value Last Year |
4 W 2018 33 | Product 1 | 0,44 | 0,33 |
4 W 2018 33 | Product 2 | 0,28 | 0,08 |
4 W 2018 33 | Product 3 | 0,94 | 1,33 |
4 W 2018 33 | Product 4 | 0,54 | 0,64 |
The most left column is the only date information I have from my data source. And as you can see, it's not a proper date colum. For this reason, I have created an additional date column in EXCEL, and I've then gone on and imported the data source into PowerBI.
I've read multiple places that I need to make an additional date table. So I've done that. I've then gone on and created a relation between the dates in my date table, and the date in my data source table. Note: the dates in my data source table ONLY goes until august 2021, meanwhile the dates in my date table has dates until Dec 31st 2021.
Now there are several measure I want to calculate. Two of the main ones are YTD and YTD -1, -2, -3 etc.
This is the YTD formula I've used: YTD = TOTALYTD(SUM(Sheet1[Value]),Dates[Date])*1000
In this case, the graph looks correct, as it only shows values from january until august.
Then I've created a measure for YTD - 1 (january to august of last year) using this formula:
The YTD -1 however shows the entire sales from 2020, and not the same period as for the YTD of this year. Basically, I want the chart to show sales from january - august 2021, which I have, and january - august 2020.
User | Count |
---|---|
20 | |
8 | |
7 | |
7 | |
6 |
User | Count |
---|---|
29 | |
12 | |
11 | |
9 | |
8 |