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

Aggregation and square

Hi,

I am trying to aggregate my data and then square, while PBI first squares and then aggregates as follow:

Input
id1id2valuesqvalue
11010010000
11020040000
12030090000
120400160000
23030090000
220600360000
23020040000
230800640000
32010010000
31020040000
31010010000

 

PBI output:

PBI output
id1id2valuesqvalue
11030050000
120700250000
220600360000
2301300770000
31030050000
32010010000
   1490000

 

Desired output

Desired output
id1id2valuesqvalue
11030090000
120700490000
220600360000
23013001690000
31030090000
32010010000
   2730000

 

is there a way to set precedence on calculation?

1 ACCEPTED SOLUTION

Hi, @Anonymous 

 

Based on your description, you may create a measure as below. The pbix file is attached in the end.

Result = 
var tab = 
SUMMARIZE(
    'Table',
    'Table'[id1],
    'Table'[id2],
    "diff",SUM('Table'[difference ])
)
var newtab = 
ADDCOLUMNS(
    tab,
    "sqdiff",
    POWER([diff],2)
)
return
SUMX(
    newtab,
    [sqdiff]
)

 

Result:

c1.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

 

Create a measure.

 

sumid2 =

var _a = CALCULATE(SUM('Table'[value]),FILTER(ALLEXCEPT('Table','Table'[id2]), 'Table'[id1] = MAX('Table'[id1])))

RETURN
_a*_a
 
1.jpg
 
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Anonymous
Not applicable

why does the total mismatch?

Anonymous
Not applicable

Another example:

 

input:

id1id2value1value2difference diff_sq
11010050502500
1102004016025600
1203005025062500
12040030370136900
2303002028078400
22060040560313600
2302002018032400
23080050750562500
32010050502500
3102002018032400
31010040603600

 

PBI output

v1.PNG

 
Desired
id1id2difference diff_sq
11021044100
120620384400
220560313600
23012101464100
31024057600
320502500
 

now power bi  adds 2500+25600 = 28100 instead of 210^2 = 44100

Hi, @Anonymous 

 

Based on your description, you may create a measure as below. The pbix file is attached in the end.

Result = 
var tab = 
SUMMARIZE(
    'Table',
    'Table'[id1],
    'Table'[id2],
    "diff",SUM('Table'[difference ])
)
var newtab = 
ADDCOLUMNS(
    tab,
    "sqdiff",
    POWER([diff],2)
)
return
SUMX(
    newtab,
    [sqdiff]
)

 

Result:

c1.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.