Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
yasbos
Resolver II
Resolver II

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 5
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

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.

vtianyichmsft_0-1700643880104.png

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.

 

 

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.

Jihwan_Kim
Super User
Super User

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]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.