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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
volod1701
Frequent Visitor

DAX CALCULATETABLE With Conditional Filtering Based on SELECTEDVALUE In Slicer

Hello!
Consider I have a single select slicer with some types 

Type_IdType_Name
1A
2B
3C
4D

 

And I have some "fact table" which has the column Type_Id

IdNameType_Id
1Row 11
2Row 22
3Row 33
4Row 44
5Row 53
6Row 64


So when I select in slicer 1 - Type A, I want to see rows with type 1, 3, 4
When I select in slicer any other type - i want to see rows only with that type

I have tried to generate a solution with AI: CALCULATETABLE with nested SWITCH or IF or TREATAS but it doesn't work.
Can anybody suggest a solution?

2 ACCEPTED SOLUTIONS
bhanu_gautam
Super User
Super User

@volod1701 Create a new measure in your fact table:

DAX
SelectedTypeRows =
VAR SelectedType = SELECTEDVALUE('Type'[Type_Id])
RETURN
IF(
SelectedType = 1,
CALCULATETABLE(
'FactTable',
'FactTable'[Type_Id] IN {1, 3, 4}
),
CALCULATETABLE(
'FactTable',
'FactTable'[Type_Id] = SelectedType
)
)

 

Use this measure in a table visual to display the filtered rows.
This measure checks if the selected type is 1. If it is, it returns rows with Type_Id 1, 3, and 4. Otherwise, it returns rows with the selected Type_Id. This should give you the desired behavior in your report.




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

v-dineshya
Community Support
Community Support

Hi @volod1701 ,

Thank you for reaching out to the Microsoft Community Forum.

 

Please  follow below steps.

 

1. Create below calculated measure 

ShowRow =
VAR SelectedType = SELECTEDVALUE ( 'Type'[Type_Id] )
VAR CurrentType = MAX ( 'Fact'[Type_Id] )
RETURN
    SWITCH(
        TRUE(),
        ISBLANK(SelectedType), 1,
        SelectedType = 1 && CurrentType IN {1, 3, 4}, 1,
        SelectedType <> 1 && CurrentType = SelectedType, 1,
        0
    )
2.  
Place this ShowRow measure on a table visual with Fact[Name], Fact[Type_Id]. Use the Visual Filter pane to filter ShowRow = 1.
 
If my response has resolved your query, please mark it as the Accepted Solution to assist others. Additionally, a 'Kudos' would be appreciated if you found my response helpful.

Thank you

View solution in original post

6 REPLIES 6
v-dineshya
Community Support
Community Support

Hi @volod1701 ,

Thank you for reaching out to the Microsoft Community Forum.

 

Please  follow below steps.

 

1. Create below calculated measure 

ShowRow =
VAR SelectedType = SELECTEDVALUE ( 'Type'[Type_Id] )
VAR CurrentType = MAX ( 'Fact'[Type_Id] )
RETURN
    SWITCH(
        TRUE(),
        ISBLANK(SelectedType), 1,
        SelectedType = 1 && CurrentType IN {1, 3, 4}, 1,
        SelectedType <> 1 && CurrentType = SelectedType, 1,
        0
    )
2.  
Place this ShowRow measure on a table visual with Fact[Name], Fact[Type_Id]. Use the Visual Filter pane to filter ShowRow = 1.
 
If my response has resolved your query, please mark it as the Accepted Solution to assist others. Additionally, a 'Kudos' would be appreciated if you found my response helpful.

Thank you

Hi @volod1701 ,

If my response has resolved your query, please mark it as the Accepted Solution to assist others. Additionally, a 'Kudos' would be appreciated if you found my response helpful.

Thank you

Hi @volod1701 ,

If my response has resolved your query, please mark it as the Accepted Solution to assist others. Additionally, a 'Kudos' would be appreciated if you found my response helpful.

Thank you

Hi @volod1701 ,

If my response has resolved your query, please mark it as the Accepted Solution to assist others. Additionally, a 'Kudos' would be appreciated if you found my response helpful.

Thank you

volod1701
Frequent Visitor

@bhanu_gautam 

It returns this error: "the expression refers to multiple columns. Multiple columns cannot be converted to a scalar value". As I understand, if the table must be returned, then RETURN must be followed by something that returns table explicitly. When DAX meets RETURN IF - it expects a scalar measure, not a table, it doesn't looks into the IF function implicitly, so it doesn't understand that IF returns a table in its result so this way it doesn't translate our measure to a table one, but translates to a scalar one.

bhanu_gautam
Super User
Super User

@volod1701 Create a new measure in your fact table:

DAX
SelectedTypeRows =
VAR SelectedType = SELECTEDVALUE('Type'[Type_Id])
RETURN
IF(
SelectedType = 1,
CALCULATETABLE(
'FactTable',
'FactTable'[Type_Id] IN {1, 3, 4}
),
CALCULATETABLE(
'FactTable',
'FactTable'[Type_Id] = SelectedType
)
)

 

Use this measure in a table visual to display the filtered rows.
This measure checks if the selected type is 1. If it is, it returns rows with Type_Id 1, 3, and 4. Otherwise, it returns rows with the selected Type_Id. This should give you the desired behavior in your report.




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.