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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Running Total

Hi community,

 

I would be very thankfull if you assist me to solve the issue . I have issue which could not solve for days . I am quite new in DAX . In SSAS tabular cube i already wrote DAX formula which is working fine . The issue is only when you open measure in Pivot Table or in Power BI , the grand total which appears automatically ,do not sum up values in column ,but only takes the last date's value . Overall formula calculates cumulative sum of volume of past days ,then divide it to count of working days past for each day.

 

Here is the formula : 

СредПрджРабочихДней:=

VAR CurrentDate = MAX('Календарь'[DayDate])

VAR SelectedMonth = MAX('Календарь'[MonthNo])

VAR CumulativeSalesValue =

    CALCULATE(

        [ПервПродRKA_и_ВторПрод_Дал],

        FILTER(

            ALLSELECTED('Календарь'),

            'Календарь'[DayDate] <= CurrentDate

                && 'Календарь'[MonthNo] = SelectedMonth

        ),

        ALLSELECTED('Календарь'[DayDate])

    )

VAR WorkingDaysPast =

    CALCULATE(

        COUNTROWS('Календарь'),

        FILTER(

            ALLSELECTED('Календарь'),

            'Календарь'[DayDate] <= CurrentDate

                && 'Календарь'[MonthNo] = SelectedMonth

                && 'Календарь'[DayIsHolyday] = 0

        )

    )

RETURN

    DIVIDE(CumulativeSalesValue, WorkingDaysPast)

4 REPLIES 4
Anonymous
Not applicable

Hi,

 

First of all , thank for your quick response . Unfortunately, the code above, calculates numbers not in the way i need . For example , today is 9th March of 2023 . Totally, 6 working days has past(excluding 8th - public holiday) . So for 9th March value would be ,cumulative sum of volume sales for all days past including non-working,  then divide it to the number of business days ( working days ) past. Then for the next day the same calculation . 

By the way ,your code also in Total section , takes the last day's value

Shaxa_1-1687930802680.png

Blue marked, your'c code . To his left ,mine . 

Thanks in advance.

Anonymous
Not applicable

HI @Anonymous,

It seems like the allselected function also affect the variables with max function, you can try to use the following formula if helps:

СредПрджРабочихДней =
VAR summary =
    ADDCOLUMNS (
        SUMMARIZE (
            'Календарь',
            [MonthNo],
            [DayDate],
            "CumulativeSales",
                CALCULATE (
                    [ПервПродRKA_и_ВторПрод_Дал],
                    FILTER (
                        ALLSELECTED ( 'Календарь' ),
                        'Календарь'[DayDate] <= [DayDate]
                            && 'Календарь'[MonthNo] = [MonthNo]
                    )
                ),
            "WorkingDaysPast",
                CALCULATE (
                    COUNTROWS ( 'Календарь' ),
                    FILTER (
                        ALLSELECTED ( 'Календарь' ),
                        'Календарь'[DayDate] <= [DayDate]
                            && 'Календарь'[MonthNo] = [MonthNo]
                            && 'Календарь'[DayIsHolyday] = 0
                    )
                )
        ),
        "CS/WDP", DIVIDE ( [CumulativeSales], [WorkingDaysPast] )
    )
RETURN
    SUMX ( summary, [CS/WDP] )

In addition, can you please share some dummy data that keep the raw data structure and dax expression? They should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Hi,

 

What kind of data should i provide to clarify situation? I don't know what exaclty you meant by raw data structure and dax expresison. Thanks in advance

Anonymous
Not applicable

HI @Anonymous,

You can try to add a variable with summarize function to calculate these calculations on the row level and use iterator function to aggregate these results:

СредПрджРабочихДней =
VAR summary =
    ADDCOLUMNS (
        SUMMARIZE (
            ALLSELECTED ( 'Календарь' ),
            [MonthNo],
            [DayDate],
            "CumulativeSales",
                VAR CurrentDate =
                    MAX ( 'Календарь'[DayDate] )
                VAR SelectedMonth =
                    MAX ( 'Календарь'[MonthNo] )
                RETURN
                    CALCULATE (
                        [ПервПродRKA_и_ВторПрод_Дал],
                        FILTER (
                            ALLSELECTED ( 'Календарь' ),
                            'Календарь'[DayDate] <= CurrentDate
                                && 'Календарь'[MonthNo] = SelectedMonth
                        )
                    ),
            "WorkingDaysPast",
                CALCULATE (
                    COUNTROWS ( 'Календарь' ),
                    FILTER (
                        ALLSELECTED ( 'Календарь' ),
                        'Календарь'[DayDate] <= CurrentDate
                            && 'Календарь'[MonthNo] = SelectedMonth
                            && 'Календарь'[DayIsHolyday] = 0
                    )
                )
        ),
        "CS/WDP", DIVIDE ( [CumulativeSales], [WorkingDaysPast] )
    )
RETURN
    SUMX ( summary, [CS/WDP] )

Measure Totals, The Final Word 

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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