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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
telesforo1969
Helper V
Helper V

sum and division calculation for a matrix (in a single measure)

I need to calculate three sums and one division in a single step (Measure)  to create the array shown in the image.

Each month is also calculated (Precio = Costos / Consumos)

MatrizSuma y división.JPG

2 ACCEPTED SOLUTIONS
speedramps
Super User
Super User

Thanks for the exmaple picture!

 

Try this

 

Create some test data

speedramps_2-1749057789799.png

Create a DAX measure

Answer = 
var myvariable = SELECTEDVALUE(yourdata[Variable])
var x = CALCULATE(SUM(yourdata[Value]), yourdata[Variable] = "Costos")
var y = CALCULATE(SUM(yourdata[Value]), yourdata[Variable] = "Consumos")

RETURN
IF(myvariable = "Precio", 
DIVIDE(x , y),
SUM(yourdata[Value])
)

 

Draw your matrix 

speedramps_3-1749058635469.png

 

 

Please click at least thumbs up for me trying to help.

Then click [accept solution] if it works.

 

Or provide a better description with input data as table (not a picture)
and example output. 

 

You will get a quick and better answer with no misunderstandings if you provide clear examples

View solution in original post

Muchas gracias desde México. 
The arrays with the months are no problem. I'll take care of it. Thank you very much.

MatrizSuma y división 1.JPG

View solution in original post

5 REPLIES 5
speedramps
Super User
Super User

@telesforo1969 

I am glad my solution solved your problem.

 

Please click the thumbs-up and [accept solution] button. 

 

Thank you !

speedramps
Super User
Super User

Thanks for the exmaple picture!

 

Try this

 

Create some test data

speedramps_2-1749057789799.png

Create a DAX measure

Answer = 
var myvariable = SELECTEDVALUE(yourdata[Variable])
var x = CALCULATE(SUM(yourdata[Value]), yourdata[Variable] = "Costos")
var y = CALCULATE(SUM(yourdata[Value]), yourdata[Variable] = "Consumos")

RETURN
IF(myvariable = "Precio", 
DIVIDE(x , y),
SUM(yourdata[Value])
)

 

Draw your matrix 

speedramps_3-1749058635469.png

 

 

Please click at least thumbs up for me trying to help.

Then click [accept solution] if it works.

 

Or provide a better description with input data as table (not a picture)
and example output. 

 

You will get a quick and better answer with no misunderstandings if you provide clear examples

Muchas gracias desde México. 
The arrays with the months are no problem. I'll take care of it. Thank you very much.

MatrizSuma y división 1.JPG

ajaybabuinturi
Memorable Member
Memorable Member

Hi @telesforo1969,
Could ypu please provide the data how it's looking in Power BI and what type of visual are you going to used.

Thank you. It's a matrix, and I solved it with the proposed "speedramps" code.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors