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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Help with Count based on another column

I have an example data set:

 

IDTypeQuantity
1IP1
2IP1
2OP7
3IP1

 

I want to sum the  Quantity of OP types where the unique IDs have an IP and OP Line item. IE we would only sum ID 2 which would equal 7. What Dax measure could I create to do this?

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

How about this?

 

OP with IP =
VAR CalcTable =
    ADDCOLUMNS (
        VALUES ( Table01[ID] ),
        "@HasIP", "IP" IN CALCULATETABLE ( VALUES ( Table01[Type] ) ),
        "@QtyOP", CALCULATE ( SUM ( Table01[Quantity] ), Table01[Type] = "OP" )
    )
RETURN
    SUMX ( FILTER ( CalcTable, [@HasIP] ), [@QtyOP] )

View solution in original post

8 REPLIES 8
AlexisOlson
Super User
Super User

How about this?

 

OP with IP =
VAR CalcTable =
    ADDCOLUMNS (
        VALUES ( Table01[ID] ),
        "@HasIP", "IP" IN CALCULATETABLE ( VALUES ( Table01[Type] ) ),
        "@QtyOP", CALCULATE ( SUM ( Table01[Quantity] ), Table01[Type] = "OP" )
    )
RETURN
    SUMX ( FILTER ( CalcTable, [@HasIP] ), [@QtyOP] )
KNP
Super User
Super User

Hi @Anonymous,

 

Depends on what you want to happen to the IP type rows.

Something like this?

[measure] =
CALCULATE (
    SUM ( Table[Quantity] ),
    Table[Type] = "OP"
)

 

Regards,

Kim

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
Anonymous
Not applicable

I want to ignore the IP rows, but sub the OP rows in whihc the ID was also associated with IP 

Not sure I completely follow.

Does the measure I provided do that?

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
Anonymous
Not applicable

NO this will some all IDs that are OP, I want to some IDs that were IP but now OP.

I think I got what you're after with my answer but it would help to include in your sample data rows that distinguish between just summing OP and summing OP that were previously IP. These are identical with your given example.

Anonymous
Not applicable

IDTypeQuantity
1IP1
2IP1
2OP7
3OP1
4OP8

 

So in this example we owuld only want to sum ID 2, bc its the only one that was previously IP

Yeah, I got it. I'd recommend editing that into your original post though.

 

The DAX I suggested should work fine for this example.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.