cancel
Showing results for
Did you mean:
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
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])))``

2.Create a calculated table using dax

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

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)``

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

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.

2 REPLIES 2
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])))``

2.Create a calculated table using dax

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

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)``

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

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.

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.

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)``````

Announcements

#### The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt talks about the importance of Data Modeling.

#### Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through June10th!

#### Check it Out!

Watch Session 22 Ted's Dev Camp along with past sessions!