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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
gluizqueiroz
Resolver I
Resolver I

How to create a dynamic table that always contains a especific rows even if is filtered on Power BI

I have the following table:

I have a filter by City on my page.

When I filter "Rome" for example, I need that table returns the following lines:

 

Note the cases with Type = P is affected by filter but all lines with Type = T is not affected by filter.

In other words, I need to create a table that always returns the lines with Type = T even if is filtered, but Type = P suffer the action of filter.

I tried the following DAX code:

 

CalcTable = 
UNION
(
CALCULATETABLE(VALUES(Table1[Cod]); Table1[Type] = "P");
CALCULATETABLE(VALUES(Table1[Cod]); Table1[Ind_Tipo] = "T"; ALL(Table1))
)

 

 

1 ACCEPTED SOLUTION
LivioLanzo
Solution Sage
Solution Sage

Hello @gluizqueiroz

 

You can't have dynamic tables in Power BI but you can do it like this:

 

Create data model like this, where cities contains the list of unique cities, this is what you will use in your slicer:

 

Capture.PNG

 

Then, add this measure:

 

Measure = 
CALCULATE(
    COUNTROWS( Data ),
    UNION(
        CROSSJOIN( TREATAS( {"P"}, Data[Type] ), TREATAS( VALUES( Cities[City] ), Data[City]  ) ),
        CROSSJOIN( TREATAS( {"T"}, Data[Type] ), TREATAS( ALL( Cities[City] ), Data[City] ) )
    )
)

Then, you can add a Table Visual, where you would add the columns of your 'Data' Table. Make sure each element is set to 'Do Not Summarize'. Instead of displaying the measure as an additional column as I did below, you could add it to the Visual Filters section with a condition that it has to be equal to 1:

 

Capture.PNG

Capture.PNG

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

View solution in original post

4 REPLIES 4
LivioLanzo
Solution Sage
Solution Sage

Hello @gluizqueiroz

 

You can't have dynamic tables in Power BI but you can do it like this:

 

Create data model like this, where cities contains the list of unique cities, this is what you will use in your slicer:

 

Capture.PNG

 

Then, add this measure:

 

Measure = 
CALCULATE(
    COUNTROWS( Data ),
    UNION(
        CROSSJOIN( TREATAS( {"P"}, Data[Type] ), TREATAS( VALUES( Cities[City] ), Data[City]  ) ),
        CROSSJOIN( TREATAS( {"T"}, Data[Type] ), TREATAS( ALL( Cities[City] ), Data[City] ) )
    )
)

Then, you can add a Table Visual, where you would add the columns of your 'Data' Table. Make sure each element is set to 'Do Not Summarize'. Instead of displaying the measure as an additional column as I did below, you could add it to the Visual Filters section with a condition that it has to be equal to 1:

 

Capture.PNG

Capture.PNG

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Hey @LivioLanzo!
It works perfect for my visual table, but I have a map too, can I use this technique for a map? 
My visual table is showing the correct cases, its perfect, but for my map is not working, did you know why?

I added Latitude and Longitude, and set the colors for "Type", if "Type = T" show the green balls, if the "Type = P" show red balls, green balls always should appear, like on visual table. 
Can you help me on my map too? The structure is the same, this is in the same page (Visual Table and Map and Filters)

Hello@gluizqueiroz

 

try using the same measure as a filter for the visual:

 

Capture.PNG

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Hey @LivioLanzo!
It works fine fine fine!

Thanks so much for help and tech me some new things!
You are awesome man, have a nice day!
Again, thanks so much!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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