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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Doesn't work comulative total

Hey guys,

 

I'm desperate, I don't know is something wrong with data, formula, or just me.

 

I have to tables Calendar (dates) and Item Ledger entry (item turnover data), they are related by Calendar[Date] - Item Ledger Entry [Posting Date].

 

The result should be table wich shows some other measures (sales data) regarding date filter and a colum in the end [ Stock]. Stock shows how much items we have left to last date of filter (it ignores first filter date). First of all I must calculate commulative total, and just stuck here.

 

Formula that I use:

Stock (1) = CALCULATE(
    SUM('Item ledger entry'[Quantity]),
    FILTER(ALL(Calendar),
Calendar[Date]<=MAX(Calendar[Date]))
)

It doesnt worg it gives same amount as [Quantity].

Also I tried this:

 

Stock (2) = CALCULATE(
    SUM('Item ledger entry'[Quantity]),
FILTER( ALLSELECTED(Calendar[Date]),
ISONORAFTER(Calendar[Date], MAX(Calendar[Date]), DESC))
)

It didint work eigher.

What I get:

 Comulative totoal.png

Maybe you have any ideas what i'm doing wrong?

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

HI @Anonymous,

 

You can try to use below measure formula if it works on your side:

Stock (1) =
CALCULATE (
    SUM ( 'Item ledger entry'[Quantity] ),
    FILTER (
        ALLSELECTED ( 'Item ledger entry' ),
        'Item ledger entry'[Date] <= MAX ( Calendar[Date] )
    )
)

If above not help, please share some sample data for test and coding formula.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

HI @Anonymous,

 

You can try to use below measure formula if it works on your side:

Stock (1) =
CALCULATE (
    SUM ( 'Item ledger entry'[Quantity] ),
    FILTER (
        ALLSELECTED ( 'Item ledger entry' ),
        'Item ledger entry'[Date] <= MAX ( Calendar[Date] )
    )
)

If above not help, please share some sample data for test and coding formula.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Thanks, @v-shex-msft, it works!

 

Could you bit explain why ALLSELECTED must be 'Item ledger entry' if my Data field is in 'Calendar' table? 

Hi @Anonymous,

 

Cumulative total calculation need to across multiple row which mean calculation need to ignore 'per row contents filter' effect, that is why I add it to 'Item ledger entry' table.

 

When you add all/allselected on calendar table, it only means you will get a max date from whole or filtered calendar table.

 

It will choose related records from 'Item ledger entry' table with condition 'Item ledger entry date value less than max calendar date'.

 

Reference link:

Cumulative Total

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
March Fabric Community Update

Fabric Community Update - March 2024

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

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.