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.
Hello, new to Power BI here.
I'm trying to obtain the percent changes of my data, by Years. The main issue I'm facing is that I'm using DirectQuery, and the DAX functions SAMEPERIODLASTYEAR and PREVIOUSYEAR are not available using DirectQuery, as per the documentation.
Here's a sample of how my data looks:
Year | Category | Value |
2000 | 1 | 5.65 |
2000 | 2 | 3.52 |
2001 | 1 | 4.65 |
2001 | 2 | 0.84 |
2002 | 1 | 1.54 |
2002 | 2 | 5.59 |
Ideally, I'd have a line chart with the Years in the X axis, and the values in the Y axis. I'd use the Legend option to put the Category fields.
Any ideas on how to proceed?
Solved! Go to Solution.
Hi @Anonymous ,
The major issue was the "Year" Column which was not really a date.
1. You should create a calculated column to replace "Year":
T_YEAR = DATE(Table[Year],1,1)
2. Create measure to get "value" of this year and last year:
THIS YEAR = SUMX(Table, Table[Value])
LAST_YEAR = CALCULATE(SUMX(Table,Table[Value]),PREVIOUSYEAR(Table[T_YEAR]))
3. Use "DIVIDE" function to calculate percentage change:
Percent_Change = DIVIDE([THIS YEAR]-[LAST_YEAR],[LAST_YEAR],0)
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
The major issue was the "Year" Column which was not really a date.
1. You should create a calculated column to replace "Year":
T_YEAR = DATE(Table[Year],1,1)
2. Create measure to get "value" of this year and last year:
THIS YEAR = SUMX(Table, Table[Value])
LAST_YEAR = CALCULATE(SUMX(Table,Table[Value]),PREVIOUSYEAR(Table[T_YEAR]))
3. Use "DIVIDE" function to calculate percentage change:
Percent_Change = DIVIDE([THIS YEAR]-[LAST_YEAR],[LAST_YEAR],0)
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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 |
---|---|
110 | |
97 | |
77 | |
63 | |
55 |
User | Count |
---|---|
143 | |
109 | |
89 | |
84 | |
66 |