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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
DaGemsta
Helper I
Helper I

Total column that sum's values from different rows

Hi guys

 

I'm working with the following data

 

IndexFuel InFuel OutOnBoard
89200520056383
904900011283
910011283
92013009983
93015008483
94015006983
953320010303
96808010303
97040006303
9809355368
99102010205398
1008000013398
1010013398

 

I need to create a "Check" column that will cross check everything is as it should be.

 

In Excel this is easy as I use the following formula

DaGemsta_0-1656107398935.png

Then I can see if column H matches column I. You can see from the excel version row 12 is 30 out, so that will be flagged and investigated.

 

I'm really struggling to get this working on PowerBi. I've created an Index column to help but just can't get my head around the formular.

 

I tried this calculated column

Check =
var ind = 'OnDemand'[Index]
var preind = ind-1
var postind = ind+1
var onboardPreRow =

SUMX(
FILTER(
'OnDemand',
'OnDemand'[Index] = preind
),
'OnDemand'[OnBoard]
)

var fuelinPostrow =

SUMX(
FILTER(
'OnDemand',
'OnDemand'[Index] = postind
),
[Fuel In]
)

var fueloutPostrow =

SUMX(
FILTER(
'OnDemand',
'OnDemand'[Index] = postind
),
[Fuel Out]
)

var subtotal = onboardPreRow - 'OnDemand'[OnBoard]

RETURN

subtotal + fuelinPostrow - fueloutPostrow



But its giving me an error about "a circular dependancy was detected OnDemand[Check]" so not sure what I've done wrong.

 

Can anyone help please? This is keeping me up 😞

 

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @DaGemsta ,

 

Please try this.

Check = 
VAR _ind = 'OnDemand'[Index]
VAR _preind = _ind - 1
VAR _onboardPreRow =
    CALCULATE (
        MAX ( 'OnDemand'[OnBoard] ),
        FILTER ( ALL ( 'OnDemand' ), 'OnDemand'[Index] = _preind )
    )
VAR _fuelinPostrow =
    CALCULATE (
        MAX ( 'OnDemand'[Fuel In] ),
        FILTER ( ALL ( 'OnDemand' ), 'OnDemand'[Index] = _ind )
    )
VAR _fueloutPostrow =
    CALCULATE (
        MAX ( 'OnDemand'[Fuel Out] ),
        FILTER ( ALL ( 'OnDemand' ), 'OnDemand'[Index] = _ind )
    )
VAR _subtotal = _onboardPreRow + _fuelinPostrow - _fueloutPostrow
RETURN
    _subtotal

vcgaomsft_0-1656380163877.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

I am sure you have a Date column as well.  Please share that column in a revised table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-cgao-msft
Community Support
Community Support

Hi @DaGemsta ,

 

Please try this.

Check = 
VAR _ind = 'OnDemand'[Index]
VAR _preind = _ind - 1
VAR _onboardPreRow =
    CALCULATE (
        MAX ( 'OnDemand'[OnBoard] ),
        FILTER ( ALL ( 'OnDemand' ), 'OnDemand'[Index] = _preind )
    )
VAR _fuelinPostrow =
    CALCULATE (
        MAX ( 'OnDemand'[Fuel In] ),
        FILTER ( ALL ( 'OnDemand' ), 'OnDemand'[Index] = _ind )
    )
VAR _fueloutPostrow =
    CALCULATE (
        MAX ( 'OnDemand'[Fuel Out] ),
        FILTER ( ALL ( 'OnDemand' ), 'OnDemand'[Index] = _ind )
    )
VAR _subtotal = _onboardPreRow + _fuelinPostrow - _fueloutPostrow
RETURN
    _subtotal

vcgaomsft_0-1656380163877.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.