Forum Discussion

yasbos's avatar
yasbos
Resolver II
2 years ago

Allselected doesn't work on a table variable

Hi. I have a table variable consisting of 

var TotalTime= ADDCOLUMNS(
                summarize(Tbl1 ,Tbl1[ID])
                , "Duration"
                ,calculate(
                            sum(Tbl1[duration])
                            , t2_Dim[status]<>"Complete"
                )
Now, the problem is, the below code is not causing the calculation below to be the same on every row. I need to see the grand total on every row, but I keep getting a unique value for every row, as if allselected() did not work on the table variable.
calculate(sumx(TotalTime, [Duration]), allselected())  
Does anyone know why? I know that it would work if i didn't have a table variable, but I need to summarize first, and that is why I need a variable first. Thanks so much.

5 Replies

  • Hi,

    I am not sure how your semantic model looks like, but please try something like below whether it suits your requirement.

     

    VAR TotalTime =
    SUMMARIZE (
        ADDCOLUMNS (
            SUMMARIZE ( Tbl1, Tbl1[ID], calendar[Date] ),
            "Duration",
                CALCULATE (
                    SUM ( Tbl1[duration] ),
                    t2_Dim[status] <> "Complete",
                    ALLSELECTED ( calendar )
                )
        ),
        Tbl1[ID],
        [Duration]
    )
    
    • yasbos's avatar
      yasbos
      Resolver II

      Hi. Thanks. Unfirtunately, it is not the calendar that is an issue. The whole measure works fine without a table variable. It's the variable that causes it to malfunction. I don't undredtand why. I didn't break lineage.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi yasbos ,

     

    I can't understand you clearly, but I made some attempts. The unique value case you are talking about is misplaced measure.

    T1 ALL = CALCULATE(SUMX('T1','T1'[value]),ALLSELECTED('T1'[ID]))
    
    VT ALL = CALCULATE(SUMX('VT','VT'[Duration]),ALLSELECTED('VT'[ID]))

     

    Hope it helps!

     

    Best regards,
    Community Support Team_ Scott Chang

     

    If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

     

     

    • yasbos's avatar
      yasbos
      Resolver II

      Thanks for trying, Anonymous . I see you created a calculated table. I can't create calculated tables because I aork with an analysis services tabular model. I can't create columns or calculated tables. However, my question is specific to table variables that are created within the measure for use within the measure only. What I'm sayin is that, it seems that allselected does not work on table variables. The code works fine if I doen't use table variables. My question was whether I was not doing it correctly, and if there is a way to be able to use allselected on a table variable. Thanks.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi yasbos ,

     

    Could you provide me with a sample data that maps the structure of your data, I'd like to try it out.

     

    Best regards,
    Community Support Team_ Scott Chang