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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
marcss44
Regular Visitor

Add from previous row value in a Matrix

I've got a Matrix with months in the column header and days in the row header and the value are the items count.

marcss44_0-1715852043803.png

For the 138 value on ene column and 1 row, i need to get the SUM of 138 and the previous value 537. And the recursively...

How can i do it?

1 ACCEPTED SOLUTION

Hey @marcss44 ,

 

here you go:

TotalValue Of DistinctCounts = 
SUMX(
    ALLSELECTED( 'TablaDifDias'[Value] )
    , [Some kind of DistinctCount]
)

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

9 REPLIES 9
v-shex-msft
Community Support
Community Support

Hi @marcss44 ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

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

He @marcss44 ,

 

I do not download from we transfer, I'm sorry.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hey @marcss44 ,

 

based on your sample data I use two measures to create the Matrix visual:

  1. A measure that does the distinctcount
    Because DISTINCTCOUNT is an expensive operation I use one of the optimization techniques, you can read about optimizing DISTINCTCOUNT here: Analyzing the performance of DISTINCTCOUNT in DAX - SQLBI
  2. A measure that creates the RunningSum of the DistinctCounts across the Days
    This measure is still leveraging WINDOW

The DISTINCTCOUNT measure:

Some kind of DistinctCount = 
COUNTROWS(
    VALUES( 'SDFSDG'[PEDIDO] )
)

The RunningSum measure:

RunningSum Of DistinctCounts = 
[Some kind of DistinctCount]
+
SUMX(
    WINDOW(
        1 , abs
        , -1 , rel
        , SUMMARIZE(
            ALLSELECTED( 'TablaDifDias'[Value] )
            , 'TablaDifDias'[Value]
        )
        , ORDERBY( 'TablaDifDias'[Value] , ASC )
    )
    , [Some kind of DistinctCount]
)

And the Matrix visual:
image.png

The screenshot reveals an implicit challenge/isssue of RunningSums calculations. If you do not want to have a running sum calculated for days that do not have DISTINCTCOUNT then you can use the below measure:

smarter RunningSum Of DistinctCounts = 
var currentDistinctCount = [Some kind of DistinctCount]
return
IF( NOT(ISBLANK( currentDistinctCount ) )
    , currentDistinctCount
    +
    SUMX(
        WINDOW(
            1 , abs
            , -1 , rel
            , SUMMARIZE(
                ALLSELECTED( 'TablaDifDias'[Value] )
                , 'TablaDifDias'[Value]
            )
            , ORDERBY( 'TablaDifDias'[Value] , ASC )
        )
        , [Some kind of DistinctCount]
    )
)

 

Hopefully, this provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Yeah it works, and the lasti, how can i get the sum of all values in evrey column, for example 771 for the first column, 879 for the second...

Hey @marcss44 ,

 

here you go:

TotalValue Of DistinctCounts = 
SUMX(
    ALLSELECTED( 'TablaDifDias'[Value] )
    , [Some kind of DistinctCount]
)

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
TomMartens
Super User
Super User

Hey @marcss44

please create a pbix that contains sample data but still reflects your semantic model (tables, relationships, calculated columns, and measures). Upload the pbix to OneDrive, Google Drive, or Dropbox and share the link.

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
TomMartens
Super User
Super User

Hey @marcss44 ,

 

assuming the table looks like this (I only entered a couple of values):

TomMartens_0-1715853025219.png

You can use the below measure to achieve what you want:

Measure = 
CALCULATE( SUM( 'Table'[value] ) )
+ CALCULATE(
    SUM( 'Table'[value] )
    , WINDOW(
        1 , abs
        , -1 , rel
        , SUMMARIZE(
            ALLSELECTED( 'Table'[day_diff] )
            , 'Table'[day_diff]
        )
        , ORDERBY( 'Table'[day_diff] , ASC )
    )
)

The measure is leveraging the windowing function WINDOW (WINDOW – DAX Guide😞

The Matrix visual will look like this:

image.png

I also wrote an article why WINDOW is my favorite windowing function: My favorite windowing function - WINDOW - Mincing Data - Gain Insight from Data (minceddata.info)

Hopefully, this provides what you are looking for, to tackle your challenge.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Just one step more, the value is the distinctcount of invoices not direct value

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.