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
Vennela
Frequent Visitor

Dynamic calculated column based on slicer selection

Hi,

I have a situation where the user wants to select a value from the slicer and the Power BI should calculate the columns based on the selected value. 

Below is a clear explanation of the issue. 

I have table 'A' with Threshold values that go into the slicer (1% - 100%)

Table 'B' with ID column, Network column (contains 1 or 0), and a calculated measure, Rate (in percentage format)

Now, I want to create a calculated column 'Applicable' in Table 'B' that says if the network is 1 and Rate >= selected threshold value, then 1 else, blank.

 

Table 'A'

Vennela_0-1656581752229.png

 

Table 'B'

Vennela_1-1656582202859.png

'Rate' measure in Table 'B' looks like below. It is calculated using a different table.

Vennela_2-1656582326060.png

 

I have created a measure 'Applicable', 

Applicable = IF(SUM('Table B'[Network])>0,IF([Rate]>=SELECTEDVALUE('Threshold'[Threshold]),1,0),0)

So whenever I select a value in the 'Threshold' slicer this measure is giving me the right result for each line in the visual but, the grand total is showing as zero (probably it is taking the average). Below is the screenshot.

Vennela_4-1656582924157.png

I want the grand total to show the sum of the 'Applicable' measure (In this case its 3). 

 

Is there a way to use selectedvalue in the column calculation?

I tried using the same dax to calculate a column but the selectedvalue dax is returning a null value.

Any help on this would be appreciated. 

 

Thanks,
Vennela

1 ACCEPTED SOLUTION

Hi @Vennela ,

I'm afraid that creating calculated columns doesn't do what you want (dynamically displaying values based on slicer selection). As @amitchandak said, creating a calculated column can't get the values selected by the slicer. You can check the following blogs for the answer...

Calculated Columns and Measures in DAX

Calculated Columns vs Measures

There is a big difference between calculated columns and measures. The value of a calculated column is computed during data refresh and uses the current row as a context; it does not depend on user interaction in the report. A measure operates on aggregations of data defined by the current context, which depends on the filter applied in the report – such as slicer, rows, and columns selection in a pivot table, or axes and filters applied to a chart.

Best Regards

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

View solution in original post

3 REPLIES 3
Vennela
Frequent Visitor

Hi @amitchandak, Thanks for your response. your solution is working if I create a measure. I can see the grand total showing the sum of the field. 
But, is there a workaround to create a column instead of a measure? as I have to use this column in further calculations which would be at row level hence, it should be a calculated column.

Hi @Vennela ,

I'm afraid that creating calculated columns doesn't do what you want (dynamically displaying values based on slicer selection). As @amitchandak said, creating a calculated column can't get the values selected by the slicer. You can check the following blogs for the answer...

Calculated Columns and Measures in DAX

Calculated Columns vs Measures

There is a big difference between calculated columns and measures. The value of a calculated column is computed during data refresh and uses the current row as a context; it does not depend on user interaction in the report. A measure operates on aggregations of data defined by the current context, which depends on the filter applied in the report – such as slicer, rows, and columns selection in a pivot table, or axes and filters applied to a chart.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@Vennela , You need to create measure as column do not take slicer value

 

Try like

Applicable =

sumx(Table, calculate( IF(SUM('Table B'[Network])>0,IF([Rate]>=SELECTEDVALUE('Threshold'[Threshold]),1,0),0) ))

 

 

or

 

sumx(values(Table[ID]), calculate( IF(SUM('Table B'[Network])>0,IF([Rate]>=SELECTEDVALUE('Threshold'[Threshold]),1,0),0) ))

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.