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
Laiq_Rahman
Helper I
Helper I

Need a running sum from a average measure in direct query

Hi,

 

I am connecting to a large table using direct query.

 

Here is my raw data sample :

INTERVAL_DATESTATION_NAMEDAY_TYPESTATIONIDPOPPORTFOLIOREGION_CODERRPPERIOD_IDINTERVAL_DATEIDFUELDUIDBID_AVAIL
1/04/2021 0:00AWFWDARWFOArarat WFVIC128.62620210401WindARWF128.62
1/04/2021 0:00AWFWDARWFOArarat WFVIC128.73720210401WindARWF128.73
2/04/2021 0:00AWFNWDARWFOArarat WFVIC1-12.2114920210402WindARWF1-12.21
2/04/2021 0:00AWFNWDARWFOArarat WFVIC1-12.2115020210402WindARWF1-12.21
2/04/2021 0:00AWFNWDARWFOArarat WFVIC1-2.711520210402WindARWF1-2.7
2/04/2021 0:00AWFNWDARWFOArarat WFVIC1-2.711620210402WindARWF1-2.7
1/04/2021 0:00BraratWDARWFOArarat WFVIC130.6427120210401WindARWF130.64
1/04/2021 0:00BraratWDARWFOArarat WFVIC130.6427220210401WindARWF130.64
2/04/2021 0:00BraratNWDARWFOArarat WFVIC132.745320210402WindARWF132.74
2/04/2021 0:00BraratNWDARWFOArarat WFVIC132.745420210402WindARWF132.74
2/04/2021 0:00BraratNWDARWFOArarat WFVIC132.741020210402WindARWF132.74
2/04/2021 0:00BraratNWDARWFOArarat WFVIC132.741120210402WindARWF132.74

 

First, i've created a average dax on this :

 

AVG_BID_AVAIL = CALCULATE(AVERAGE(data7_1[BID_AVAIL]), FILTER(data7_1,data7_1[BID_AVAIL] <> 0))

 

 

Second, i'm trying to create running total based on measure "AVG_BID_AVAIL"

 

running total = CALCULATE(
    [AVG_BID_AVAIL]
    ,FILTER(
                    ALLSELECTED('data7_1'),
                        data7_1[STATION_NAME] <= MAX(data7_1[STATION_NAME]))
    , data7_1[BID_AVAIL] > 0
)

 

But it didn't work as expected and end up below figures.

Laiq_Rahman_1-1712126522931.png

I need the output should be like below : 

 

Laiq_Rahman_0-1712126500045.png

 

Please let me know how can i make this work.

 

thanks.

 

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

Hi @Laiq_Rahman 

 

Please try this:
First of all, add a index column in power query:

vzhengdxumsft_0-1712203617522.png

Then create a measure:

running total =
VAR _currentIndex =
    SUM ( 'data7_1'[Index] )
VAR _AVG_Table =
    ADDCOLUMNS (
        SUMMARIZE (
            ALL ( data7_1 ),
            'data7_1'[STATION_NAME],
            "_Index", SUM ( data7_1[Index] ),
            "_AVG_BID", [AVG_BID_AVAIL]
        ),
        "sum",
            SUMX (
                FILTER (
                    SUMMARIZE (
                        ALL ( data7_1 ),
                        'data7_1'[STATION_NAME],
                        "_Index", SUM ( data7_1[Index] ),
                        "_AVG_BID", [AVG_BID_AVAIL]
                    ),
                    [_Index] <= EARLIER ( [_Index] )
                ),
                [_AVG_BID]
            )
    )
RETURN
    MAXX ( FILTER ( _AVG_Table, [_Index] = _currentIndex ), [sum] )

 The result is as follow:

vzhengdxumsft_1-1712203653735.png

 

Best Regards

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

View solution in original post

5 REPLIES 5
v-zhengdxu-msft
Community Support
Community Support

Hi @Laiq_Rahman 

 

Please try this:
First of all, add a index column in power query:

vzhengdxumsft_0-1712203617522.png

Then create a measure:

running total =
VAR _currentIndex =
    SUM ( 'data7_1'[Index] )
VAR _AVG_Table =
    ADDCOLUMNS (
        SUMMARIZE (
            ALL ( data7_1 ),
            'data7_1'[STATION_NAME],
            "_Index", SUM ( data7_1[Index] ),
            "_AVG_BID", [AVG_BID_AVAIL]
        ),
        "sum",
            SUMX (
                FILTER (
                    SUMMARIZE (
                        ALL ( data7_1 ),
                        'data7_1'[STATION_NAME],
                        "_Index", SUM ( data7_1[Index] ),
                        "_AVG_BID", [AVG_BID_AVAIL]
                    ),
                    [_Index] <= EARLIER ( [_Index] )
                ),
                [_AVG_BID]
            )
    )
RETURN
    MAXX ( FILTER ( _AVG_Table, [_Index] = _currentIndex ), [sum] )

 The result is as follow:

vzhengdxumsft_1-1712203653735.png

 

Best Regards

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

Laiq_Rahman
Helper I
Helper I

nope.. 

Laiq_Rahman_0-1712138731419.png

 

Laiq_Rahman
Helper I
Helper I

Nope.. not working.. Getting below result

Laiq_Rahman_0-1712138045545.png

 

vs_7
Responsive Resident
Responsive Resident

Hi @Laiq_Rahman ,

try below measure

Running Total = SUMX(
    FILTER(
        ALL('data7_1'),
        'data7_1'[STATION_NAME] <= MAX('data7_1'[STATION_NAME]) &&
        'data7_1'[INTERVAL_DATE] <= MAX('data7_1'[INTERVAL_DATE])
    ),
    [AVG_BID_AVAIL]
)
vs_7
Responsive Resident
Responsive Resident

hi @Laiq_Rahman 

RunningTotal = 
VAR CurrentRowDate = MIN(data7_1[INTERVAL_DATE])
RETURN
CALCULATE(
    [AVG_BID_AVAIL],
    FILTER(
        ALLSELECTED(data7_1),
        data7_1[INTERVAL_DATE] <= CurrentRowDate    )
)

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.