March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello Community,
New to powerbi and I have data as in table 1.
Table1:
Id | Year | Country | City | Sales | Profit | Difference |
1 | 2020 | India | Delhi | 100 | 50 | -50 |
2 | 2021 | India | Mumbai | 200 | 90 | -110 |
3 | 2022 | India | Delhi | 300 | 150 | -150 |
4 | 2020 | Nigeria | Abuja | 50 | 10 | -40 |
5 | 2021 | Nigeria | Lagos | 30 | 20 | -10 |
6 | 2022 | Nigeria | Abuja | 55 | 40 | -15 |
7 | 2020 | Zimbabwe | Harare | 60 | 20 | -40 |
8 | 2021 | Zimbabwe | Harare | 30 | 25 | -5 |
9 | 2022 | Zimbabwe | Harare | 50 | 19 | -31 |
Now, I have to create a chart/table visual where I have to show prior year data w.r.t City-Country (as measure) for each current year selection (as in table below).
Expected output:
Id | Year | Country | City | Sales | Profit | Difference | Prior year sales | Prior year profit | Prior year difference |
1 | 2020 | India | Delhi | 100 | 50 | -50 | 0 | 0 | 0 |
2 | 2021 | India | Mumbai | 200 | 90 | -110 | 0 | 0 | 0 |
3 | 2022 | India | Delhi | 300 | 150 | -150 | 100 | 50 | -50 |
4 | 2020 | Nigeria | Abuja | 50 | 10 | -40 | 0 | 0 | 0 |
5 | 2021 | Nigeria | Lagos | 30 | 20 | -10 | 0 | 0 | 0 |
6 | 2022 | Nigeria | Abuja | 55 | 40 | -15 | 50 | 10 | -40 |
7 | 2020 | Zimbabwe | Harare | 60 | 20 | -40 | 0 | 0 | 0 |
8 | 2021 | Zimbabwe | Harare | 30 | 25 | -5 | 60 | 20 | -40 |
9 | 2022 | Zimbabwe | Harare | 50 | 19 | -31 | 30 | 25 | -5 |
Please can anyone help me here
Thanks,
Joseph
Hi @AnthonyJoseph ,
These three measures are below:
Prior year sales =
VAR _prior =
TOPN (
1,
FILTER (
ALLSELECTED ( 'Table' ),
[Country] = SELECTEDVALUE ( 'Table'[Country] )
&& [City] = SELECTEDVALUE ( 'Table'[City] )
&& [Year] < SELECTEDVALUE ( 'Table'[Year] )
),
[Year], DESC
)
RETURN
SUMX ( _prior, [Sales] )
Prior year profit =
VAR _prior =
TOPN (
1,
FILTER (
ALLSELECTED ( 'Table' ),
[Country] = SELECTEDVALUE ( 'Table'[Country] )
&& [City] = SELECTEDVALUE ( 'Table'[City] )
&& [Year] < SELECTEDVALUE ( 'Table'[Year] )
),
[Year], DESC
)
RETURN
SUMX ( _prior, [profit] )
Prior year difference = [Prior year profit]-[Prior year sales]
Pbix file in the end you can refer.
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks @v-chenwuz-msft I can see the data populated correctly without any slicer selection (from year) but when I choose a year from the slicer, all previous year values are turing to be 0.
Without any slicer selection I can see previous year data (example 2022 - India)
If selection is made then the preious year value is blank/zero.
Please can you help me to show previous value even when the slicer selection is made.
Thanks
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
21 | |
14 | |
11 | |
8 | |
5 |
User | Count |
---|---|
24 | |
21 | |
20 | |
15 | |
10 |