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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
joao_costa
New Member

Create calculated measure and use it as filter

I have a table with transactions and want to count the transactions by country to then group those and then use as a filter.

 

I got to the transaction count using a measure:

country_count = 

CALCULATE(
    DISTINCTCOUNT('Table'[trx_id]),
    ALLSELECTED('Table'[Country]))
 
My goal is then to group these, say by intervals of 50 up to 200 (then "200+"), and use that as a filter in a slicer.
I am able to use a simple if statement to derive that but then it does not work as a filter in the slicer.
 
Any ideas on how to solve?
TY
 
1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @joao_costa ,

 

Here's my solution.

1.country_count is measure, and is created as 

country_count = CALCULATE(DISTINCTCOUNT('Table'[trx_id]),FILTER(ALLSELECTED('Table'),[Country]=MAX('Table'[Country])))

 

vstephenmsft_1-1636965980228.png

 

2.Create a calculated table using dax

Table 2 = GENERATESERIES ( 1, MAXX('Table',[country_count]))

vstephenmsft_0-1636965962770.png

 

3.Then create a measure, put it in the filter, set show items when the value is 1.

Measure = IF([country_count]<=MAX('Table 2'[Value])&&MIN('Table 2'[Value])<=[country_count],1)

vstephenmsft_2-1636966101044.png

4.The slicer is created using value field from Table 2. No relationship between two tables. The slicer can move the slider to filter.

vstephenmsft_3-1636966134848.png

 

 

Check more details from the attachment.

 

 

Best Regards,

Stephen 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

2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @joao_costa ,

 

Here's my solution.

1.country_count is measure, and is created as 

country_count = CALCULATE(DISTINCTCOUNT('Table'[trx_id]),FILTER(ALLSELECTED('Table'),[Country]=MAX('Table'[Country])))

 

vstephenmsft_1-1636965980228.png

 

2.Create a calculated table using dax

Table 2 = GENERATESERIES ( 1, MAXX('Table',[country_count]))

vstephenmsft_0-1636965962770.png

 

3.Then create a measure, put it in the filter, set show items when the value is 1.

Measure = IF([country_count]<=MAX('Table 2'[Value])&&MIN('Table 2'[Value])<=[country_count],1)

vstephenmsft_2-1636966101044.png

4.The slicer is created using value field from Table 2. No relationship between two tables. The slicer can move the slider to filter.

vstephenmsft_3-1636966134848.png

 

 

Check more details from the attachment.

 

 

Best Regards,

Stephen Tao

 

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

 

 

 

skeets20
Resolver I
Resolver I

Created a Calculation Group with Each of your grouping (and the logic) as calculated items. Then use the calc group as your slicer.

 

calcgroupslicer2.gif

skeets20_1-1636568999366.png

 

The DAX for each item looks like this. I parameterized the bounds so you can use same logic in each item, just change the bounds. Watch out for overlapping items though

 

 

 

VAR _lowerBound = 0
VAR _upperBound = 4
VAR _summary =
    CALCULATETABLE (
        VALUES ( 'txn'[country] ),
        FILTER (
            SUMMARIZE ( 'txn', 'txn'[country], "_count", DISTINCTCOUNT ( 'txn'[Index] ) ),
            [_count] >= _lowerBound
                && [_count] <= _upperBound
        )
    )
RETURN
  CALCULATE(SELECTEDMEASURE(),  _summary)

 

 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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