Forum Discussion
Dynamic Column calculation based on Slicer Selection
- Anonymous9 years ago
Hi LeranPowerBI
Try the following
1. Create a table called MonthTable consisting of only MonthNames
MonthNames
Jan
Feb
.....
Dec
2. Use this Column MonthName from this MonthTable as a slicer for selecting month.
3. In your data table create a measure called SelectedMonthValue
SelectedMonthValue = IF(HASONEFILTER(MonthTable[MonthName]),
LOOKUPVALUE((YourTable[Amount]),YourTable[Month],Values(MonthTable[MonthName]))
,1)What this does is finds the value of Amount from YourTable ( data table) for the selectedmonth in the slicer. If no value is selected in slicer it is set to 1.
4. Now the magic
Create a measure called Relative in YourTable.
Relative = SUMX(YourTable,Divide(YourTable[Amount],[SelectedMonthValue]))
What this does is it iterates YourTable row by row and then calculates the relative value for that row.
Sample screen shot with the data provided by you
If this solves your issue, please accept it as a solution and also give KUDOS.
Cheers
CheenuSing
HI lxiaoxi,
The issue is the SelectedMonthValue is a calculated column and not a measure. Note the calculated columns are computed only once on refresh. They do not get computed for every change in the value of slicers. As per the formula the value of HASONEFILTER(fieldname) is null and therefore all values are evaluated to If not value 1.
If you can elaborate on what you want to actually achieve, then may be I can try to help. If possible place the pbix or data in google drive or OneDrive and share the link here.
Cheers
CheenuSing
Hi Anonymous
Is there any way that the month selected in Slicer will reflects as a value in data table.
Regards,
Gaurav More