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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
pbhat89
Helper II
Helper II

Conditional tables using DAX or other methods

I have a tables as below :

Table 1 - granularity level is VID,NID - unique combination key

VIDNIDAgeHeight
a134167
a223156
b354189
b465187
b523160
c612189
d756188

 

Table 2 - granularity level is VID,NID,condition- unique combination key. note VID , NID can repeat with different conditions

VIDNIDCondition
a2x1
d7x2

 

 

Target is to achieve tables ( caluculated or temp ) after following options to filter 

 

FILTERS (only for e.g. set below)

Age  <=50

Height <=190

Condition = X1 [this is required as anti filter , i.e. remove not keep]

 

Expected tables to be generated and refreshed (as filters changed)

 

Table 3 - filtered table 

VIDNIDAgeHeight
a134167
b523160
c612189

 

a,2 was removed as it had x1 condition and b4,b3 were removed due to age filter

 

Table 4 ( Except (all ( Table 1) , table 3) : i.e. all records that were filtered out from main table

VIDNIDAgeHeight
b354189
b465187
a223156

 

Once these two tables are generated, i will create calculations based on that. how do i create these tables as temp or permamnent tables in power bi ( interactively updating as filters change ) 

6 REPLIES 6
v-yangliu-msft
Community Support
Community Support

Hi  @pbhat89 ,

 

As far as I know, it seems that this requirement can not be implemented, because whether it is a table filtered from power query or exported to CSV after filtering, the table generated by Excel is a fixed table and will not change with the filter.


Best Regards,

Liu Yang

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

v-yangliu-msft
Community Support
Community Support

Hi  @pbhat89 ,

Here are the steps you can follow:

1. Enter power query, home – merge queries as new through transform data, select the columns associated with the two tables, and perform left outer

v-yangliu-msft_0-1607303509332.jpeg

Merge into table merge1:

v-yangliu-msft_1-1607303509336.png

2. Create calculated table.

 

Table3 =

var _1=SUMMARIZE('Merge1',

'Merge1'[VID],'Merge1'[NID],

"Age",CALCULATE(SUM('Merge1'[Age]),FILTER('Merge1','Merge1'[Age]<=50&&'Merge1'[Height]<=190&&'Merge1'[Table2.Condition]=BLANK())),

"Height",CALCULATE(SUM(Merge1[Height]),FILTER('Merge1','Merge1'[Age]<=50&&'Merge1'[Height]<=190&&'Merge1'[Table2.Condition]=BLANK())))

return FILTER(_1,[Age]<>BLANK())

 

 The results of Table 3 are as follows

2020.12.7.1.jpg

Table4 =

var _1=

SUMMARIZE('Merge1',

'Merge1'[VID],'Merge1'[NID],

"Age",CALCULATE(SUM(Merge1[Age]),FILTER('Merge1',('Merge1'[Age]>=50 ||'Merge1'[Table2.Condition]="x1")&&'Merge1'[Table2.Condition]<>"x2")),

"Height",CALCULATE(SUM(Merge1[Height]),FILTER('Merge1',('Merge1'[Age]>=50 || 'Merge1'[Table2.Condition]="x1")&&'Merge1'[Table2.Condition]<>"x2")))

return FILTER(_1,[Age]<>BLANK())

 The results of Table 4 are as follows

2020.12.7.2.jpg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

 

Liu, thanks. But in your table 3 and 4 above you seem to be using fixed filter values i.e. Age >= 50. this the value which will be a filter in the dashboard which user can input , hence this has to be variable and not tied to 50. Hence the need to keep updating table 3, 4 as values change. 

MFelix
Super User
Super User

Hi @pbhat89 ,

 

Not really sure about the final outcome you are expecting but making it a step by step you need to add the following measure to your model:

 

FIltering = 

var selectedNid = VALUES('Table (2)'[NID])
var selectedVID = VALUES('Table (2)'[VID])
Return
IF(SELECTEDVALUE('Table'[NID]) in   selectedNid && SELECTEDVALUE('Table'[VID]) in selectedVID; BLANK();1)

 

Now has you can see when you select the values on the slicers the table only gets the result you need.

 

My question is what is the calculation you need to have? you only show the filtered table result but what do you want to have in the end? Asking this because you will need to have a temporary table created but i without knowing what is the final result you need I cannot assist in helping you wiht the code since this depends on context.

 

Checkl PBIX file attach.

 

Believe this is repeated with the post below:

 

https://community.powerbi.com/t5/Desktop/Conditional-table-using-Dax-query-on-the-fly/m-p/1526109


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks MFelix. There are various calculations that is difficult for me to describe in the example above - hence for me it is ideal to have temp / changing conditional tables based on which i can create those calculations else i have to use long NOT in , IF ELSE kind of statements . For better idea to you - two calculations is :

 

Distinct Count of NID ( table 3 ) - but excluding the common NID in table 4 - hence only "C" = Count = 1

Distinct Count of NID ( table 4 ) - but excluding the common NID in table 4 - hence only "B,A" = Count = 2

 

As mentioned, there are many other calculations from other values that i need to do. Hence i need table 3 , 4 to be created on the fly so that i can reference the columns directly from these tables that are updated each time a filter is applied. Is that possible ? Recently i tried to create a copy of table 1 , then use merge as new and selected left anti join - hoping that as i apply filters , i will be left with the right table but it shows 0 rows each time as if it doesnt detect the realtime applied filters. 

 

 

 

Hi @pbhat89 ,

 

Without full details about your model I cannot help you about the best alternative what I can do is refer to two possible soluitions:

 

Dynamic M query Parameters - Allows to do a parameter based on a slicer this is on preview since October.

https://powerbi.microsoft.com/en-us/blog/power-bi-october-2020-feature-summary/#_Toc51665421

https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-dynamic-m-query-parameters

https://blog.crossjoin.co.uk/2020/10/25/why-im-excited-about-dynamic-m-parameters-in-power-bi/

 

And the othe option can be the calcution groups:

 

https://docs.microsoft.com/en-us/analysis-services/tabular-models/calculation-groups?view=asallprodu...

https://www.fourmoo.com/2020/04/29/how-to-create-and-use-calculation-groups-in-power-bi-premium-azur...

 

Hope this can guide you in a correct path.

 

If you need further assistance please tell me.

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.