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 Everyone,
Can you help me create DAX for image below? (The image below is just an example based on the actual report). I created a slicer for each Services and System ID. Each system ID and Services is unique. The loyalty category is based on support for 5 years.
Loyal = Customers have purchased support each year in the last 5 years
Potentially Loyal = customers have purchase support 3 or 4 out of the last 5 years
Transient = customers have purchase support 2 out of the last 5 years or 1 of the last 5 years but not in the current year
New = customers have purchased support this year for the first time in 5 years.
Former & Non-Purchasing = customers have never purchased support in the last 5 years
The DAX I created for Loyalty Category is below:
Solved! Go to Solution.
@lbendlin , thanks for your concern about this case. I tried to create a sample data myself based on the user's requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:
Hi @JB17 ,
I created some data:
Here are the steps you can follow:
1. Use Enter data – create a table.
2. Select [Service] – Column tools – Sort by column – [Index].
Because Power BI's default sorting is alphabetical, we need to create an lndex to control the sorting order
3. Create measure.
Category Sum of Years =
VAR _today =
TODAY ()
VAR _current =
YEAR ( _today )
VAR _last5years = _current - 4
VAR _count =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Year] ),
FILTER (
ALL ( 'Table' ),
'Table'[Year] >= _last5years
&& 'Table'[Year] <= _current
&& 'Table'[Services] = MAX ( 'Service_Table'[Services] )
&& 'Table'[System ID] = MAX ( 'Table'[System ID] )
)
)
VAR _if =
IF ( _count = BLANK (), 0, _count )
VAR _currentcount =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Year] ),
FILTER (
ALL ( 'Table' ),
'Table'[Year] = _current
&& 'Table'[Services] = MAX ( 'Service_Table'[Services] )
&& 'Table'[System ID] = MAX ( 'Table'[System ID] )
)
)
VAR _column =
SELECTCOLUMNS (
FILTER (
ALL ( 'Table' ),
'Table'[Services] = MAX ( 'Service_Table'[Services] )
&& 'Table'[System ID] = MAX ( 'Table'[System ID] )
),
"test", _if
)
VAR _sw =
SWITCH (
TRUE (),
5 IN _column, "Loyal",
4
IN _column
|| 3 IN _column, "Potentially Loyal",
OR ( 2 IN _column, 1 IN _column )
&& _currentcount = BLANK (), "Transient",
1
IN _column
&& _currentcount <> BLANK (), "New"
)
RETURN
IF ( _count = 0, "Former & Non-Purchasing", _sw )
4. Result:
If the results don't meet your expectations, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
@lbendlin , thanks for your concern about this case. I tried to create a sample data myself based on the user's requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:
Hi @JB17 ,
I created some data:
Here are the steps you can follow:
1. Use Enter data – create a table.
2. Select [Service] – Column tools – Sort by column – [Index].
Because Power BI's default sorting is alphabetical, we need to create an lndex to control the sorting order
3. Create measure.
Category Sum of Years =
VAR _today =
TODAY ()
VAR _current =
YEAR ( _today )
VAR _last5years = _current - 4
VAR _count =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Year] ),
FILTER (
ALL ( 'Table' ),
'Table'[Year] >= _last5years
&& 'Table'[Year] <= _current
&& 'Table'[Services] = MAX ( 'Service_Table'[Services] )
&& 'Table'[System ID] = MAX ( 'Table'[System ID] )
)
)
VAR _if =
IF ( _count = BLANK (), 0, _count )
VAR _currentcount =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Year] ),
FILTER (
ALL ( 'Table' ),
'Table'[Year] = _current
&& 'Table'[Services] = MAX ( 'Service_Table'[Services] )
&& 'Table'[System ID] = MAX ( 'Table'[System ID] )
)
)
VAR _column =
SELECTCOLUMNS (
FILTER (
ALL ( 'Table' ),
'Table'[Services] = MAX ( 'Service_Table'[Services] )
&& 'Table'[System ID] = MAX ( 'Table'[System ID] )
),
"test", _if
)
VAR _sw =
SWITCH (
TRUE (),
5 IN _column, "Loyal",
4
IN _column
|| 3 IN _column, "Potentially Loyal",
OR ( 2 IN _column, 1 IN _column )
&& _currentcount = BLANK (), "Transient",
1
IN _column
&& _currentcount <> BLANK (), "New"
)
RETURN
IF ( _count = 0, "Former & Non-Purchasing", _sw )
4. Result:
If the results don't meet your expectations, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information or anything not related to the issue or question.
If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...
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 |
---|---|
13 | |
13 | |
12 | |
8 | |
7 |
User | Count |
---|---|
18 | |
14 | |
11 | |
11 | |
9 |