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
kellyylt
Helper I
Helper I

Constant Column for Table Based on Measure

Hello! I am trying to create a table below in Direct Query mode and am struggling with the last step. I am trying to count the number of items in a table based on status and want to have another column (Count 2) with constant value based on the 'Status' column.

 

I have tried CALCULATE(SUM(Table[Qty]), FILTER(ALL(Table), Table[Status] = "A")) and a few other variations but the rows in Status B and C are always 0.

 

Can someone please help on this?

 

StatusCount 1Count 2
ACount number items with Status ACount number items with Status A
BCount number of items with Status BCount number of items with Status A
CCount number of items with Status C Count number of items with Status A

 

1 ACCEPTED SOLUTION

you mean with measure? you can try to create with two measures with such code:

    Count1 = CALCULATE( COUNTROWS( TableName ) ),

    Count2 = CALCULATE( COUNTROWS( TableName ), TableName[Status] = "A" )
 
try to plot a Table Visual, with Status column and the two measures.

View solution in original post

8 REPLIES 8
vicky_
Super User
Super User

Do you need the FILTER statement for something? Try removing it and seeing what the output is.
The current problem is the rows of the table already apply a filter that you won't see in the DAX formula. So in the row with status B, your formula will calculate no values with status = A. Not sure if that made sense, but I hope it helps.

Yes, I am trying to calculate values with Status = A for rows with Status = B and Status = C too. If I just use ALL(Table), I will sum up all the statuses which is not what I am looking for.

FreemanZ
Community Champion
Community Champion

what do you mean by "constant value based on the 'Status' column."?

I mean achieving what I'd shown in 'Count 2' column. I need the rows to ignore the row context of 'Status' column except for Status A

aha, then try to create a new table with the code below:

 
Table =
ADDCOLUMNS(
    VALUES( TableName[Status] ),
    "Count1",
    CALCULATE( COUNTROWS( TableName ) ),
    "Count2"
    CALCULATE( COUNTROWS( TableName ), TableName[Status] = "A" )
)

Thanks!! This worked. Is there a way to acheive this without the use of tables?

you mean with measure? you can try to create with two measures with such code:

    Count1 = CALCULATE( COUNTROWS( TableName ) ),

    Count2 = CALCULATE( COUNTROWS( TableName ), TableName[Status] = "A" )
 
try to plot a Table Visual, with Status column and the two measures.

Thanks! This measure worked. It wasn't working on mine as I just realised there's another table filtering the contents.

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.