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
Anonymous
Not applicable

SUMX with modifications

Hi,

I have a table with 3 columns, Item, Unit of Measure, and Quantity.

 

 

ItemUnit of MeasureQuantity
Akg1
Bmg1000000
Cmg1000000
Amg1000000


I want to add a measure to sum the quantities, but differently depending on the Unit of Measure for each row. If Unit of Measure = "kg", then Quantity X 1000000, else Quantity.

 

The resulting table would look like the following:

ItemTotal
A2000000
B1000000
C1000000
2 ACCEPTED SOLUTIONS
AlB
Super User
Super User

Hi @Anonymous

 

Try this, where Table1 is the table you show:

 

1. Set Table1[ID] in the rows of a matrix visual

2. Create this measure and place it in values of the matrix:

 

Measure =
SUMX (
    Table1,
    IF (
        Table1[Unit of Measure] = "kg",
        Table1[Quantity] * 1000000,
        Table1[Quantity]
    )
)

View solution in original post

Greg_Deckler
Super User
Super User

So, something like:

 

Measure = 
VAR __table = SUMMARIZE('Table4',[Item],[Unit of Measure],"__quantity",IF([Unit of Measure]="kg",SUM([Quantity])*1000000,SUM([Quantity])))
RETURN
SUMX(__table,[__quantity])

?

 

See attached Table 4, Page 3


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

So, something like:

 

Measure = 
VAR __table = SUMMARIZE('Table4',[Item],[Unit of Measure],"__quantity",IF([Unit of Measure]="kg",SUM([Quantity])*1000000,SUM([Quantity])))
RETURN
SUMX(__table,[__quantity])

?

 

See attached Table 4, Page 3


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
AlB
Super User
Super User

Hi @Anonymous

 

Try this, where Table1 is the table you show:

 

1. Set Table1[ID] in the rows of a matrix visual

2. Create this measure and place it in values of the matrix:

 

Measure =
SUMX (
    Table1,
    IF (
        Table1[Unit of Measure] = "kg",
        Table1[Quantity] * 1000000,
        Table1[Quantity]
    )
)

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.