Hi @BrianJ, @AntrikshSharma, Others
While working on solution for below Task, I am facing an issue with using ALLSELECTED inside calculation.I have identified the WorkAround but need to understand the issue. Request your help on this.
Requirement- Based on Filter, Need to get values for Last maximum field value of the current Evaluation Context in visual.
In example, I am using a Filter on Dates[MonthnYear], In table visual I need to get [Total Sales] for previous MonthnYear from fitler Selections and for Total values, need to get Sum of [Total Sales] of all the Rows.
Working Solution - I am able to make it work using below measure by creating a separate table using ALLSELECTED outside main expression.
AllSel-SepTab =
var AllSelectedDates = SUMMARIZE(ALLSELECTED(Dates[MonthnYear]),Dates[MonthnYear])
var TabFinal =
ADDCOLUMNS (
ADDCOLUMNS (
ADDCOLUMNS (
SUMMARIZE ( VALUES ( Dates[MonthnYear] ), Dates[MonthnYear] ),
"maxdate", CALCULATE ( MAX ( Dates[MonthnYear] ) )
),
"prev",
CALCULATE (
MAX ( Dates[MonthnYear] ),
FILTER ( AllSelectedDates, Dates[MonthnYear] < [maxdate] )
)
),
"Sales", CALCULATE ( [Total Sales], FILTER ( AllSelectedDates, Dates[MonthnYear] = [prev] ) )
)
return
sumx(TabFinal,[sales])
Problem : I am facing issue when I am trying below i.e. using ALLSELECTED inside main Filter expression. Here for individual Rows I am getting blank.
AllSel-InsideCalc =
//var AllSelectedDates = SUMMARIZE(ALLSELECTED(Dates[MonthnYear]),Dates[MonthnYear])
var TabFinal =
ADDCOLUMNS (
ADDCOLUMNS (
ADDCOLUMNS (
SUMMARIZE ( VALUES ( Dates[MonthnYear] ), Dates[MonthnYear] ),
"maxdate", CALCULATE ( MAX ( Dates[MonthnYear] ) )
),
"prev",
CALCULATE (
MAX ( Dates[MonthnYear] ),
FILTER ( ALLSELECTED(Dates[MonthnYear]), Dates[MonthnYear] < [maxdate] )
)
),
"Sales", CALCULATE ( [Total Sales], FILTER ( ALLSELECTED(Dates[MonthnYear]), Dates[MonthnYear] = [prev] ) )
)
return
sumx(TabFinal,[sales])
I have also tried with ALL function and it is working in both the scenarios. Can check measure All-SepTab, All-InsideCalc as shown in diagram also.
Can you pls suggest why ALLSELECTED inside Filter condition is not working. Attached the PBIX.AllSelected Help.pbix (394.8 KB)
Thanks
Ankit J