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
praveenlc
Helper I
Helper I

Table level calculation

Hi, I am stuck with achieving table level calculation, any quick help is appreciated. it could be a measure or column 

 

Problem is to pick the appropriate cell value and subtract it against the previous cell value

I tried few dax but no luck

total = CALCULATE(SUM('Facttable (2)'[Value]),ALLEXCEPT('Facttable (2)','Facttable (2)'[Fleet No]))
total - cellvalue = 
CALCULATE(SUM('Facttable (2)'[Value]),ALLEXCEPT('Facttable (2)','Facttable (2)'[Fleet No])) - CALCULATE(SUM('Facttable (2)'[Value]),FILTER(ALLEXCEPT('Facttable (2)','Facttable (2)'[Fleet No]),'Facttable (2)'[Index]-1))
IDEndWeekValueIndexExpected Results Calculation  
1150110/7/201824236310 Default "0"If Index=1 then 0 
1150111/4/201824871126348 "=C3-C2"248711 - 242363Index1-Index2
1150112/2/201825316334452 "=C4-C3"253163 - 248711Index2-Index3
1150112/31/201825886945706 "=C5-C4"  
115011/27/201926455955690 "=C6-C5"  
115012/24/201927015165592 "=C7-C6"  
234883/24/201927426910 Default "0"  
234884/21/201927991625647 "=C9-C8"  
234885/19/201928385933943 "=C10-C9"  
234886/16/201929055546696 "=C11-C10"  
234887/14/201929474254187 "=C12-C11"  
1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @praveenlc ,

 

I don't see a Fleet No in your example, but the following calculated column should work for the data you posted:

myResult = 
VAR vCurrentValue = Facttable[Value]
VAR vCurrentIndex = Facttable[Index]
RETURN
    IF(
        vCurrentIndex = 1,
        0,
        vCurrentValue - CALCULATE(SUM(Facttable[Value]), Facttable[Index] = vCurrentIndex - 1 , ALLEXCEPT(Facttable, Facttable[ID]))
    )

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

5 REPLIES 5
selimovd
Super User
Super User

Hey @praveenlc ,

 

I don't see a Fleet No in your example, but the following calculated column should work for the data you posted:

myResult = 
VAR vCurrentValue = Facttable[Value]
VAR vCurrentIndex = Facttable[Index]
RETURN
    IF(
        vCurrentIndex = 1,
        0,
        vCurrentValue - CALCULATE(SUM(Facttable[Value]), Facttable[Index] = vCurrentIndex - 1 , ALLEXCEPT(Facttable, Facttable[ID]))
    )

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

hi @selimovd thanks and appreciate your quick response

 

I did try VAR on index but was not aware that VAR could be used for values also.

 

Thanks again!

Best wishes

Hey @praveenlc ,

 

I'm happy it works 😊

Yes, VAR is pretty dynamic, you can save the result of measures, the current column value or a row like done here and also whole tables, for example with the SUMMARIZE or VALUES function.

 

Best regards

Denis

praveenlc
Helper I
Helper I

ID EndWeekValueIndexExpected Results Calculation  
11501    10/7/201824236310 Default "0"If Index=1 then 0 
11501   11/4/201824871126348 "=C3-C2"248711 - 242363Index1-Index2
11501    12/2/201825316334452 "=C4-C3"253163 - 248711Index2-Index3
11501    12/31/201825886945706 "=C5-C4"  
11501    1/27/201926455955690 "=C6-C5"  
11501    2/24/201927015165592 "=C7-C6"  
23488    3/24/201927426910 Default "0"  
23488    4/21/201927991625647 "=C9-C8"  
23488    5/19/201928385933943 "=C10-C9"  
23488    6/16/201929055546696 "=C11-C10"  
23488    7/14/201929474254187 "=C12-C11"  

ID EndWeek Value IndexExpected Results Calculation  
11501 10/7/2018 242363 10 Default "0"If Index=1 then 0 
11501 11/4/2018 248711 26348 "=C3-C2"248711 - 242363Index1-Index2
11501 12/2/2018 253163 34452 "=C4-C3"253163 - 248711Index2-Index3
11501 12/31/2018 258869 45706 "=C5-C4"  
11501 1/27/2019 264559 55690 "=C6-C5"  
11501 2/24/2019 270151 65592 "=C7-C6"  
23488 3/24/2019 274269 10 Default "0"  
23488 4/21/2019 279916 25647 "=C9-C8"  
23488 5/19/2019 283859 33943 "=C10-C9"  
23488 6/16/2019 290555 46696 "=C11-C10"  
23488 7/14/2019 294742 54187 "=C12-C11"  

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.