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
samdthompson
Memorable Member
Memorable Member

LASTNONBLANK & Totals in Matrix

My head is hurting after trying to figure this out, pretty sure the answer is in using LASTNONBLANK but i just cant get it to work. I have a series of suppliers who own shares. Those suppliers are in groups. I want to be able to see the shareholding of the groups as at any point in time. The current state of the matrix I have is this:

 

Current        
GroupSupplier1/12/202015/12/202028/12/20201/01/202112/01/202128/01/20212/02/2021
1A500    100 
 B400     300
 C200  250   
Group1Total 1100002500100300
2X300350     
 Y400    100 
Group2Total 7003500001000
GrandTotal 180035002500200300

 

and I want to produce this:

EndState          
GroupSupplier1/12/202015/12/202028/12/20202020Total1/01/202112/01/202128/01/20212/02/20212021Total
1A500500500500500500550550550
 B400400400400400400400300300
 C200200200200250250250250250
Group1Total 110011001100110011501150120011001100
2X300350350350350350350350350
 Y400400400400400400100100100
Group2Total 700750750750750750450450450
GrandTotal 180018501850185019001900165015501550

 

My starting point is:

 

TotalShares = SUM(Data[Shares]), it works fine.

 

My attempt to get the endstate table was this:

 

=CALCULATE([TotalShares],LASTNONBLANK(Date[Date],SUM(Data[Shares])

 

It shouldnt be this hard surely?

 

 

 

// if this is a solution please mark as such. Kudos always appreciated.
1 ACCEPTED SOLUTION

@v-lionel-msft, thanks but its not quite right. The totals on 01/28/2021 should read:

 

group 1: 750 (100+400+250)

group 2: 450 (350+100)

grand total: 1200 (750+450)

 

I like your solution for the dates though, havent thought of that approach before.

// if this is a solution please mark as such. Kudos always appreciated.

View solution in original post

7 REPLIES 7
samdthompson
Memorable Member
Memorable Member

Bump 

// if this is a solution please mark as such. Kudos always appreciated.
v-lionel-msft
Community Support
Community Support

Hi @samdthompson ,

 

Please refer to my .pbix file.

v-lionel-msft_0-1614236698848.png

 

Best regards,
Lionel Chen

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

@v-lionel-msft, thanks but its not quite right. The totals on 01/28/2021 should read:

 

group 1: 750 (100+400+250)

group 2: 450 (350+100)

grand total: 1200 (750+450)

 

I like your solution for the dates though, havent thought of that approach before.

// if this is a solution please mark as such. Kudos always appreciated.
v-lionel-msft
Community Support
Community Support

Hi @samdthompson ,

 

Please provide sample data in tabular form.

 

Best regards,
Lionel Chen

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

hi @v-lionel-msft, heres a screen shot and the pbix is: PBIX example 

 

samdthompson_0-1613587881762.png

 

// if this is a solution please mark as such. Kudos always appreciated.
samdthompson
Memorable Member
Memorable Member

Hello, thanks @mahoneypat but it didnt work completely. The group totals do repeat successfully but the grand total is incorrect. If both groups have a chage on the same day its fine but if there is just one group changing the grand total sums up only that.

// if this is a solution please mark as such. Kudos always appreciated.
mahoneypat
Employee
Employee

Please try this measure expression instead

 

NewMeasure =
VAR vThisDate =
    MAX ( Date[Date] )
RETURN
    CALCULATE (
        LASTNONBLANKVALUE (
            Date[Date],
            [Total Shares]
        ),
        FILTER (
            ALL ( Date[Date] ),
            Date[Date] <= vThisDate
        )
    )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.