Forum Discussion

belvoir99's avatar
belvoir99
Resolver III
11 months ago
Solved

Manipulating slicer values with single column tables

My slicer has a number of values (2, 3, 4, 5). (2, 3) is the first pair and (4,5) is the second pair. The slicer can't be broken up into two slicers. Most of the behaviours work fine except the last ...
  • belvoir99's avatar
    belvoir99
    11 months ago

    wardy912 thanks so much for your code - it almost works but errors out on the line

    SENPYD[SENPupilGroup] IN SENValues

     This is the same problem I was having, namely that the SENValues single column table is produced from an IF statement which doesn't allow a table as an output. 

    Some interesting ideas here though! So thanks very much!

    I have now (I think, subject to final testing) found the solution - which might be of interest to you:

    SSUM Test = 
    VAR AllTable = VALUES(PupilYearData[PupilSchoolDataID])
    VAR SexSlicer = CALCULATE( SELECTEDVALUE(PupilGroup[PupilGroupID]), PupilGroup[PupilGroupID] IN {2, 3} )
    VAR SexValues = SELECTCOLUMNS( FILTER( ADDCOLUMNS( GENERATESERIES(2, 3), "NewCol", IF( ISBLANK(SexSlicer), [Value], SexSlicer) ), [Value] = [NewCol] ), "Result", [Value] )
    
    VAR SENSlicer = CALCULATE( SELECTEDVALUE(PupilGroup[PupilGroupID]), PupilGroup[PupilGroupID] IN {4, 5} )
    VAR SENValues = SELECTCOLUMNS( FILTER( ADDCOLUMNS( GENERATESERIES(4, 5), "NewCol", IF( ISBLANK(SENSlicer), [Value], SENSlicer) ), [Value] = [NewCol] ), "Result", [Value] )
    
    VAR FinalCount = 
        IF( MIN(PupilGroup[PupilGroupID]) = 1, 
            COUNTROWS(AllTable),
            CALCULATE(
                COUNTROWS(PupilYearData),
                Sex[SexPupilGroupID] IN SexValues, 
                SENPYD[SENPupilGroup] IN SENValues
            )
        )
    RETURN
    FinalCount

    The code is a bit too concise here (sorry) but with some formatting it'll be a bit more readable. I had to apply the technique for SENValues onto SexValues too.
    Copilot and SQLBI were my friends here plus a little bit of hard thinking! 🙂
    SexValues returns either (2), (3) or (2, 3) as single column table, and particularly returns (2,3) even if the two slicer values are unticked.
    I took (2, 3) from GENERATESERIES (can also use DATATABLE) and then added another column which got its value from the slicer value. If the slicer value is blank (i.e. > 1 value) then put in the first column value otherwise put the slicer value.
    Finally filter the rows so that only the match between first and second column are returned.