Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi, I have the following dataset:
Periode | Kundenr | Rating | Saldo | Changenr | ChangeID | |
31.12.2024 | 1 | 1 | 10 | 3 | Better | |
31.12.2024 | 2 | 2 | 11 | 1 | Better | |
31.12.2024 | 3 | 1 | 12 | 3 | Better | |
31.12.2024 | 4 | Default | 13 | Default | Default | |
31.12.2024 | 5 | 2 | 14 | 0 | Unchanged | |
31.12.2024 | 6 | 3 | 15 | 0 | Unchanged | |
31.12.2024 | 7 | 4 | 16 | -1 | Worse | |
31.12.2024 | 8 | 5 | 17 | -1 | Worse | |
31.12.2024 | 9 | 4 | 18 | 0 | Unchanged | |
31.12.2024 | 10 | 2 | 19 | 2 | Better | |
31.12.2024 | 11 | 3 | 20 | 2 | Better | |
31.12.2024 | 12 | 4 | 21 | -2 | Worse | |
31.12.2024 | 13 | 5 | 22 | -3 | Worse | |
31.12.2024 | 14 | 2 | 23 | 1 | Better | |
31.12.2024 | 15 | 3 | 24 | 1 | Better | |
31.12.2024 | 22 | 2 | 11 | New | New | |
31.12.2023 | 1 | 4 | 9 | 1 | Better | |
31.12.2023 | 2 | 3 | 10 | -1 | Worse | |
31.12.2023 | 3 | 4 | 11 | -2 | Worse | |
31.12.2023 | 4 | 5 | 12 | -2 | Worse | |
31.12.2023 | 5 | 2 | 13 | 2 | Better | |
31.12.2023 | 6 | 3 | 14 | 2 | Better | |
31.12.2023 | 7 | 3 | 15 | 1 | Better | |
31.12.2023 | 8 | 4 | 16 | 1 | Better | |
31.12.2023 | 9 | 4 | 17 | -2 | Unchanged | |
31.12.2023 | 10 | 4 | 18 | -2 | Worse | |
31.12.2023 | 11 | 5 | 19 | -2 | Worse | |
31.12.2023 | 12 | 2 | 20 | New | New | |
31.12.2023 | 13 | 2 | 21 | New | New | |
31.12.2023 | 14 | 3 | 22 | New | New | |
31.12.2023 | 15 | 4 | 23 | New | New | |
31.12.2023 | 16 | 5 | 24 | New | New | |
31.12.2023 | 17 | 2 | 25 | New | New | |
31.12.2023 | 18 | 3 | 26 | New | New | |
31.12.2023 | 19 | 4 | 27 | New | New | |
31.12.2023 | 20 | 3 | 28 | New | New | |
31.12.2023 | 21 | 4 | 29 | New | New | |
31.12.2022 | 1 | 5 | 8 | New | New | |
31.12.2022 | 2 | 2 | 9 | New | New | |
31.12.2022 | 3 | 2 | 10 | New | New | |
31.12.2022 | 4 | 3 | 11 | New | New | |
31.12.2022 | 5 | 4 | 12 | New | New | |
31.12.2022 | 6 | 5 | 13 | New | New | |
31.12.2022 | 7 | 4 | 14 | New | New | |
31.12.2022 | 8 | 5 | 15 | New | New | |
31.12.2022 | 9 | 2 | 16 | New | New | |
31.12.2022 | 10 | 2 | 17 | New | New | |
31.12.2022 | 11 | 3 | 18 | New | New |
Column F and G are calculated. I want to write a dax that can give me those values. Or even better! The change between periods chosen by a slicer:)
I also want to be able to present it like this:
To rating | 1 | 2 | 3 | 4 | 5 | Unchanged | Worse | Better | Default | Gone | |
From rating | |||||||||||
2024 | 1 | 0 | 0 | 0 | |||||||
2 | 25 | 21 | 22 | 25 | 43 | 0 | 25 | ||||
3 | 34 | 15 | 16 | 15 | 16 | 34 | 54 | ||||
4 | 32 | 19 | 24 | 18 | 17 | 18 | 17 | 75 | 56 | ||
5 | 13 | 20 | 0 | 0 | 33 | 13 | 24 | ||||
Sum | 58 | 76 | 142 | 13 | 159 |
I have only done it for the period 2023-2024, but here it also would be nice to make it dynamic between chosen periodes.
As you can see this also gives me a problem. How about those Kundenr. that are gone. Like customer 16... between 2023-2024. They are presented in the matrix as gone.
Any ideas on how to solve this would be highly appreciated, thanks!
Im sorry for not knowing have to upload the data if that would help:/
Hi @nor303
To solve your problem, we can use DAX to dynamically calculate the transitions between the periods selected by a slicer, and to handle scenarios such as customers that are no longer present ("Gone"). We'll first calculate the ChangeNr column, which represents the difference in ratings between the current and previous periods for each Kundenr. This can be achieved with the following DAX formula:
ChangeNr =
VAR CurrentPeriod = MAX('Table'[Periode])
VAR PreviousPeriod = CALCULATE(MAX('Table'[Periode]), 'Table'[Periode] < CurrentPeriod)
VAR CurrentRating = MAX('Table'[Rating])
VAR PreviousRating = CALCULATE(MAX('Table'[Rating]), 'Table'[Periode] = PreviousPeriod && 'Table'[Kundenr] = EARLIER('Table'[Kundenr]))
RETURN
IF(
ISBLANK(PreviousRating),
BLANK(),
CurrentRating - PreviousRating
)
Next, we calculate the ChangeID column to categorize the change (e.g., "Better," "Worse," "Unchanged"). This column determines the nature of the change based on the value of ChangeNr. The formula for this is as follows:
ChangeID =
VAR Change = [ChangeNr]
RETURN
SWITCH(
TRUE(),
ISBLANK(Change), "New",
Change > 0, "Better",
Change < 0, "Worse",
Change = 0, "Unchanged",
"Default"
)
For identifying "Gone" customers (those present in the previous period but not in the current period), we can use a measure. This measure checks whether a customer exists in the earlier period but not in the later period:
Gone =
VAR CurrentPeriod = MAX('Table'[Periode])
VAR PreviousPeriod = CALCULATE(MAX('Table'[Periode]), 'Table'[Periode] < CurrentPeriod)
RETURN
IF(
NOT(ISBLANK(CALCULATE(MAX('Table'[Kundenr]), 'Table'[Periode] = PreviousPeriod))) &&
ISBLANK(CALCULATE(MAX('Table'[Kundenr]), 'Table'[Periode] = CurrentPeriod)),
1,
0
)
To create a transition matrix that dynamically calculates the "From Rating" and "To Rating" based on the selected periods, we use the following measure. This measure evaluates the rating transitions for each Kundenr:
Transition =
VAR CurrentPeriod = MAX('Table'[Periode])
VAR PreviousPeriod = CALCULATE(MAX('Table'[Periode]), 'Table'[Periode] < CurrentPeriod)
VAR FromRating = CALCULATE(MAX('Table'[Rating]), 'Table'[Periode] = PreviousPeriod && 'Table'[Kundenr] = EARLIER('Table'[Kundenr]))
VAR ToRating = CALCULATE(MAX('Table'[Rating]), 'Table'[Periode] = CurrentPeriod && 'Table'[Kundenr] = EARLIER('Table'[Kundenr]))
RETURN
IF(
ISBLANK(FromRating) || ISBLANK(ToRating),
BLANK(),
FromRating & " -> " & ToRating
)
For the matrix visualization, we use the calculated From Rating and To Rating columns as the rows and columns, respectively. The values in the matrix represent the count of Kundenr for each transition. Additionally, we create a measure to count customers classified as "Gone" for a selected period:
Gone Customers Count =
CALCULATE(
COUNTROWS('Table'),
'Table'[Gone] = 1
)
This approach allows for a dynamic and interactive matrix visualization where the transitions and categories adjust based on the slicer selection. By incorporating measures for detecting "Gone" customers and dynamically calculating transitions, you can create a complete and responsive solution in Power BI. Let me know if further clarification or adjustments are needed!
Best regards,
Thanks so much, but I have some problems still: Changenr. calculates the "wrong" way for me. I get numbers for period 2023 2022 and not 2024. It should be for 2024 2023 and 2022 are "New".
I also get a error with the ChangeID column with sircular reference. Any Ideas on have to solve this?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
116 | |
82 | |
45 | |
42 | |
28 |
User | Count |
---|---|
182 | |
82 | |
71 | |
48 | |
45 |