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
bml123
Post Patron
Post Patron

How to do sum of column from the calculated table

Hi,

 

I have a measure with calculated table,

 

CALCULATEDTABLE(

   SUMMARIZE('Table', 'Table[ClientId]',

                         "Amount_2018",CALCULATE(SUM([Amount]),'Table[Date]'=maxDate,newClients),

                         "Amount_2019",CALCULATE(SUM([Amount]),'Table[Date]'=nextYear,newClients),
                          "Diff",(CALCULATE(SUM([Amount]),'Table[Date]'=nextYear,newClients) -                                                       CALCULATE(SUM([Amount]),'Table[Date]'=maxDate,newClients)),
                         "%_change",iferror((CALCULATE(SUM([Amount]),'Table[Date]'=nextYear,newClients) -                                         CALCULATE(SUM([Amount]),'Table[Date]'=maxDate,newClients))/CALCULATE(SUM([Amount]),'Table[Date]'=maxDate,newClients))

     ),newClients

)

 

return sum(Diff) where %_change<=-0.02 and %_change>=0.02


I want to return the sum of diff from the calculated table where %_change <=-0.02 and %_change>=0.02. How do I achieve this?

 

3 REPLIES 3
amitchandak
Super User
Super User

@bml123 ,  a measure

 

measure =
var _tab = CALCULATEDTABLE(

SUMMARIZE('Table', 'Table[ClientId]',

"Amount_2018",CALCULATE(SUM([Amount]),'Table[Date]'=maxDate,newClients),

"Amount_2019",CALCULATE(SUM([Amount]),'Table[Date]'=nextYear,newClients),
"Diff",(CALCULATE(SUM([Amount]),'Table[Date]'=nextYear,newClients) - CALCULATE(SUM([Amount]),'Table[Date]'=maxDate,newClients)),
"%_change",iferror((CALCULATE(SUM([Amount]),'Table[Date]'=nextYear,newClients) - CALCULATE(SUM([Amount]),'Table[Date]'=maxDate,newClients))/CALCULATE(SUM([Amount]),'Table[Date]'=maxDate,newClients))

),newClients

)

 

return sumx(filter(_tab, _tab[%_change]<=-0.02 && _tab[%_change]>=0.02 ), _tab[Diff])

Hi @amitchandak ,

 

It didn't work.  It's giving an error at _tab[%_change] saying 'Cannot find name [%_change]' and 'cannot find name '[Diff]'

Hi @bml123 ,

 

Based on way of @amitchandak, you need to remove the variable table name before the columns, i.e. like below. Otherwise it will report an error.

 

...
return
    SUMX ( FILTER ( _tab, [%_change] <= -0.02 && [%_change] >= 0.02 ), [Diff] )

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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.