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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Evan4
Frequent Visitor

Calculating total value of invoices where certain Product ID's exist

Hello!

 

I have a question that I haven’t been able to figure out nor find an answer to on the internet… so I thought I could ask here and someone may have an answer for me!

 

I need to calculate the total value of all invoices that contain certain Product ID’s.

 

Note: Just in case someone jumps the gun, I know how to use the calculate function to find the total value of certain product ID’s. Find below how I can do this.

 

CALCULATE([Sales]

         ,FILTER(

            ALL('Product'[Product ID])

              ,'Product'[Product ID]="100"

              ||'Product'[Product ID]="101"

              ||'Product'[Product ID]="102")

)

 

However this is not what I am after unfortunately. I need the total value of invoices where these Product ID's exist.

 

If anyone has any idea it would be much appreciated!

1 ACCEPTED SOLUTION
v-sihou-msft
Employee
Employee

@Evan4

 

In this scenario, you need to use a CALCULATETABLE() to filter the corresponding Invoice first. Then use it to filter source table for your calculation. Please refer to my sample below:

 

Measure = CALCULATE (
    SUM ( Table1[Value] ),
    FILTER (
        VALUES ( Table1[Invoice] ),
        CALCULATE (
            COUNTROWS (
                CALCULATETABLE (
                    VALUES ( Table1[Invoice] ),
                    Table1[ProductID] = 100
                        || Table1[ProductID] = 101
                        || Table1[ProductID] = 102
                )
            )
        )
    )
)

555.PNG

 

 

Regards,

View solution in original post

1 REPLY 1
v-sihou-msft
Employee
Employee

@Evan4

 

In this scenario, you need to use a CALCULATETABLE() to filter the corresponding Invoice first. Then use it to filter source table for your calculation. Please refer to my sample below:

 

Measure = CALCULATE (
    SUM ( Table1[Value] ),
    FILTER (
        VALUES ( Table1[Invoice] ),
        CALCULATE (
            COUNTROWS (
                CALCULATETABLE (
                    VALUES ( Table1[Invoice] ),
                    Table1[ProductID] = 100
                        || Table1[ProductID] = 101
                        || Table1[ProductID] = 102
                )
            )
        )
    )
)

555.PNG

 

 

Regards,

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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