Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
kalkhudary
Helper IV
Helper IV

Dax - number of accounts that switched their codes more than twice in a year and magnitude of switch

Hello, 

I am stumbled on a dax. I am looking into this scenario to resolve. I have Account Numbers, Rate Codes, YearMonth(Text date type). I am looking to get the number of accounts that switched their codes more than twice in a year. Then I also want to calculate the magnitude of code switching for each account. I have the distinct counts of rate categories in the values of a matrix table and when i filter it to look into>2, it does filter the "Different Rate Codes Used Column" or the Total Column instead of the numbers that is showing under the year. 

 

The intended output is to show i each year any rate codes that occurred more than twice in each of year 2021, 2022, 2023, 2024 only and filter out the ones that has number 1 or 2. Then, I need to measure the magnitutude of code switch for each account in the 4 years. Any ideas of how to dax it these 2 scenarios. Much appreciated.

 

SNIP.PNG

 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @kalkhudary ,

Due to the limitations of the matrix itself, it may not be feasible to implement filtering of Value values in the matrix with your data. You would need a measure or calculated column to calculate the number of repeated codes and put them into the Value of the matrix, but then you would not be able to filter the values of individual cells in the matrix.
My suggestion is that you either switch to table visual objects:

Codes = DISTINCTCOUNT(YourTable[RATE CATEGORY])

And use this DAX as a filter:

Filter = 
IF(
    [Codes] < 3,
    0,
    1
)

vjunyantmsft_0-1731552894732.png


Either that or just skip this step:

vjunyantmsft_1-1731552953086.png

Directly display the results after filtering:

repeated codes = 
VAR _Count = DISTINCTCOUNT(YourTable[RATE CATEGORY])
RETURN
IF(
    _Count < 3,
    BLANK(),
    _Count
)

vjunyantmsft_2-1731553002578.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @kalkhudary ,

Can you show me what your original data structure looks like? Different data structures lead to completely different DAX.
If you want to filter out values ​​greater than 2 in this data, you need to use DAX as a filter:

vjunyantmsft_0-1731378640082.png

But this also requires knowing your original data structure, thank you!

Best Regards,
Dino Tao

@Anonymous My data is just one table and I am using it to geenrate measures. Dropping you here a sample of it with one account number sample that you can dax.

 

BKPERIODACCOUNT NUMBERRATE CATEGORYCustomer Code_2BK Year
202408211PG-C-GT2C2024
202409211PG-C-GT2C2024
202407211PG-C-GT2C2024
202409211PG-C-GS2C2024
202408211PG-C-GS2C2024
202406211PG-C-GT1C2024
202407211PG-C-GS2C2024
202406211PG-C-GS1C2024
202404211PG-C-GT1C2024
202403211PG-C-GT1C2024
202405211PG-C-GT1C2024
202404211PG-C-GS1C2024
202403211PG-C-GS1C2024
202405211PG-C-GS1C2024
202402211PG-C-GT1C2024
202401211PG-C-GT1C2024
202402211PG-C-GS1C2024
202401211PG-C-GS1C2024
202312211PG-C-GT1C2023
202311211PG-C-GT1C2023
202312211PG-C-GS1C2023
202311211PG-C-GS1C2023
202310211PG-C-GT1C2023
202309211PG-C-GT1C2023
202309211PG-C-GS1C2023
202310211PG-C-GS1C2023
202307211PG-C-GT1C2023
202308211PG-C-GT1C2023
202306211PG-C-GS2C2023
202308211PG-C-GS1C2023
202307211PG-C-GS1C2023
202305211PG-C-GT2C2023
202306211PG-C-GT2C2023
202304211PG-C-GS2C2023
202305211PG-C-GS2C2023
202303211PG-C-GT2C2023
202304211PG-C-GT2C2023
202302211PG-C-GT2C2023
202302211PG-C-GS2C2023
202303211PG-C-GS2C2023
202301211PG-C-GT2C2023
202212211PG-C-GT2C2022
202212211PG-C-GS2C2022
202301211PG-C-GS2C2023
202210211PG-C-GT2C2022
202211211PG-C-GT2C2022
202211211PG-C-GS2C2022
202210211PG-C-GS2C2022
202209211PG-C-GT2C2022
202208211PG-C-GT2C2022
202207211PG-C-GT2C2022
202209211PG-C-GS2C2022
202208211PG-C-GS2C2022
202207211PG-C-GS2C2022
202206211PG-C-GT2C2022
202206211PG-C-GS2C2022
202205211PG-C-GT2C2022
202204211PG-C-GS2C2022
202204211PG-C-GS2C2022
202205211PG-C-GS2C2022

Hi,

Based on the table that you have shared, show the expected result very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@asasasas Based on data above and as explained in the prompt, I need a dax that looks into the total number of repeated codes in each year where I can use as a filter to show accounts that has 3 repeated codes only for example and blanking the others that are less than 3.

Step1 Result:

Account Number2021202220232024
2210234

Step 2 Result After Filter:

Account Number2021202220232024
221  34
Anonymous
Not applicable

Hi @kalkhudary ,

Due to the limitations of the matrix itself, it may not be feasible to implement filtering of Value values in the matrix with your data. You would need a measure or calculated column to calculate the number of repeated codes and put them into the Value of the matrix, but then you would not be able to filter the values of individual cells in the matrix.
My suggestion is that you either switch to table visual objects:

Codes = DISTINCTCOUNT(YourTable[RATE CATEGORY])

And use this DAX as a filter:

Filter = 
IF(
    [Codes] < 3,
    0,
    1
)

vjunyantmsft_0-1731552894732.png


Either that or just skip this step:

vjunyantmsft_1-1731552953086.png

Directly display the results after filtering:

repeated codes = 
VAR _Count = DISTINCTCOUNT(YourTable[RATE CATEGORY])
RETURN
IF(
    _Count < 3,
    BLANK(),
    _Count
)

vjunyantmsft_2-1731553002578.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.