Forum Discussion
Use measure in FILTER function
Hi,
I'm trying to use the FILTER function to create a subtable based on the value of one of the columns. when I input a scalar value directly is working, however, when using the vlaue from a calculated measure is not working.
Could anyone please help me to see how I could use the measure within the filter?
I cannot direclty use the scalar since the value I need to use is dynamically changing based on a slicer.
Thanks a lot in advance
Hi LauraBueno
You'll need to create a disconnected slicer - this is a slicer that won't filter other visuals in your report.
To do this, you need create a new table using the following DAX expression:
DisconnectedTable = ALL ( 'db_datareader Simulation'[Study], 'db_datareader Simulation'[Simulation] )Then create the following measures:
Total Value = SUM ( 'db_datareader Simulation'[Value] )Delta = VAR Sim_Ref = SELECTEDVALUE ( DisconnectedTable[Simulation] ) VAR Value_Ref = CALCULATE ( SUM ( 'db_datareader Simulation'[Value] ), 'db_datareader Simulation'[Simulation] = Sim_Ref ) VAR SumVal = [Total Value] VAR Result = SumVal - Value_Ref RETURN ResultIn your report, add two slicers:
- 'db_datareader Simulation'[Study]
- 'DisconnectedTable'[Simulation]
Then add a table visualisation with the following columns from the 'db_datareader Simulation' table:
- Study
- Simulation
- Type
- Value
- [Delta] measure
You'll find that your Simulation slicer won't automatically filter depending on your selection in the Study slicer.
If you want this to work, you can create the measure below and add it to the Simulation slicer as a visual filter and set the value to 1.
SlicerFilter = VAR SelStudy = SELECTEDVALUE ( 'db_datareader Simulation'[Study] ) VAR SimStudy = SELECTEDVALUE ( DisconnectedTable[Study] ) VAR Result = IF ( SimStudy = SelStudy, 1, 0 ) RETURN ResultThis is the result I got using the data you provided:
Fingers crossed, this will work for you!
Best regards,
Martyn
23 Replies
- MartynRamsdenSolution Sage
Hi LauraBueno
Can you provide the full DAX expression in which you're using the FILTER function?
Is it a measure or a calculated column?
Best regards,
Martyn
- LauraBuenoHelper III
Hi MartynRamsden,
Thank you for your reply. Please see below the full expression where I'm using FILTER function:
Ref_table = FILTER('db_datareader S','db_datareader S'[Simulation] = 'db_datareader Simulation'[Reference_Sim_Id])I'm trying to create a subtable by filtering the datatable 'db_datareader S' based on its column 'Simulation', so that the new table only contains the rows from the original table where Simulation column equals the value given by the measure 'db_datareader Simulation'[Reference_Sim_Id].If instead of 'db_datareader Simulation'[Reference_Sim_Id], I use directly the value from the measure (i.e. 1714), then it works.I'm wondering how I could use the measure 'db_datareader Simulation'[Reference_Sim_Id] directly in that expression?ThanksLaura- MartynRamsdenSolution Sage
Hi LauraBueno
If I understand correctly, you're trying to create a calculated table 'on the fly'? If so, this isn't supported.
Calculated tables (and columns) are only computed when the data is refreshed.
What's your ultimate result? There may be an alternative method to achieve what you're looking for.
Best regards,
Martyn
- V-lianl-msftCommunity SupportHi LauraBueno ,Please refer to this thread:https://community.powerbi.com/t5/Desktop/Filtering-using-a-measure-insidea-calculate-function/m-p/847750If the problem persists,could you please share sample data and the result you expected?Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- LauraBuenoHelper III
Hi V-lianl-msft ,
Thank you for your message. I did try the solution described in the post you shared. However, it is not completely working for me.
The picture below shows the sample data I have:
There are several studies and each study with multiple simulations. The variable I am intersted in is 'value' which also depends on the column called 'type'.
What I am trying to do is, 1) Select study via slicer in dashboard (which is link to simulations and hence the slicer for simulations automatically change), 2) Select reference simulation via a different slicer. 3) For the simulation selected in the slicer, I need to do the following calculation:
Value (for all simulations for a fiven study) - Value of simulation selected in slicer filtered by 'Type'.
Could you please help me with this? Thank you so much in advance!