The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi all, new to Power BI, so thank you for your help.
I need help tweaking my DAX. I have a spreadsheet for a data source. It has a list of clients, years, region, and a measure.
Sample:
Year1 | Key | Type | Region | Count | DateYear |
2010 | 20039423 | Breakaway | EUROPE | 1 | 01/01/2010 |
2010 | 20048145 | Still | NORTH AMERICA | 1 | 01/01/2010 |
2010 | 20069080 | Still | EUROPE | 1 | 01/01/2010 |
2010 | 20199484 | Ambiant | EUROPE | 1 | 01/01/2010 |
2010 | 20200079 | Breakaway | EUROPE | 1 | 01/01/2010 |
2010 | 20200128 | Ambiant | ASIA | 1 | 01/01/2010 |
2010 | 20200213 | Still | EUROPE | 1 | 01/01/2010 |
2010 | 20200417 | Ambiant | ASIA | 1 | 01/01/2010 |
2010 | 20200698 | Glass | ASIA | 1 | 01/01/2010 |
2010 | 20200700 | Glass | AUSTRALIA | 1 | 01/01/2010 |
2010 | 20200728 | Breakaway | EUROPE | 1 | 01/01/2010 |
2010 | 20201136 | Breakaway | ASIA | 1 | 01/01/2010 |
I want to show Year over Year values. I was able to do this for just the Year (though the Total for my column isn't right):
The column definition:
zPrevYearCount3 =
VAR PriorYear = MAX('Sheet1'[Open Year]) -1
VAR Result =
SUMX(
FILTER(
ALL(Sheet1),
'Sheet1'[Open Year] = PriorYear
),
'Sheet1'[Count]
)
RETURN
Result
But, when I add the Region in, the results aren't right:
This isn't actually the ideal way I want to present it. I want to put the years across the top and Region/other attributes down the side, but I can't even get this to work (I assume this is easier like this rather than my preferred way). Thanks.
Solved! Go to Solution.
Hi, @jsgambel
Column:
zPrevYearCount3 =
VAR PriorYear =
MAX ( 'Sheet1'[Open Year] ) - 1
VAR Result =
SUMX (
FILTER (
ALL ( Sheet1 ),
'Sheet1'[Open Year] = PriorYear
&& [Region] = EARLIER ( 'Sheet1'[Region] )
),
'Sheet1'[Count]
)
RETURN
Result
Measure:
zPrevYearCount3 =
VAR PriorYear =
MAX ( 'Sheet1'[Open Year] ) - 1
VAR Result =
SUMX (
FILTER (
ALL ( Sheet1 ),
'Sheet1'[Open Year] = PriorYear
&& [Region] = SELECTEDVALUE ( 'Sheet1'[Region] )
),
'Sheet1'[Count]
)
RETURN
Result
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @jsgambel
Column:
zPrevYearCount3 =
VAR PriorYear =
MAX ( 'Sheet1'[Open Year] ) - 1
VAR Result =
SUMX (
FILTER (
ALL ( Sheet1 ),
'Sheet1'[Open Year] = PriorYear
&& [Region] = EARLIER ( 'Sheet1'[Region] )
),
'Sheet1'[Count]
)
RETURN
Result
Measure:
zPrevYearCount3 =
VAR PriorYear =
MAX ( 'Sheet1'[Open Year] ) - 1
VAR Result =
SUMX (
FILTER (
ALL ( Sheet1 ),
'Sheet1'[Open Year] = PriorYear
&& [Region] = SELECTEDVALUE ( 'Sheet1'[Region] )
),
'Sheet1'[Count]
)
RETURN
Result
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks @v-zhangti . The measure worked for me. I'll use the column if/when I need it.
@jsgambel Try:
zPrevYearCount3 =
VAR PriorYear = MAX('Sheet1'[Open Year]) -1
VAR Result =
SUMX(
FILTER(
ALLEXCEPT(Sheet1,[Region]),
'Sheet1'[Open Year] = PriorYear
),
'Sheet1'[Count]
)
RETURN
Result
Thanks for the reply @Greg_Deckler
I had to make one small change to make it work:
@jsgambel It's hard to replicate with the given sample data since it only includes a single year.
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
21 | |
19 | |
18 | |
15 | |
12 |
User | Count |
---|---|
38 | |
36 | |
22 | |
21 | |
17 |