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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
BrunoM
Advocate I
Advocate I

Repeat the total sales for each raw of a period using on a virtual table

Dear all, i need your help on a tricky (tricky for me) dax question.

CONTEXT
:
Following the Sales table :
ImpactedMonth      SRK   Sales EUR

20240320,00
202403119666,77
202404312,40
20240440,00
202404110,00
2024041259037,50
202405545,54
20240560,00
202405130,00
20240514136,63
2024051919724,71
202405200,00
20240616147,02
202406749,01
20240680,00
202406150,00
2024062149,01
202406220,00
2024062543502,17
202406260,00
202407240,00
202407100,00
202407170,00
2024071891,90
2024072330,63
202407930,63
2024072767,39
202407280,00
202407290,00
2024073019804,35

 

Using a table visual i want to display for each raw, the total sales of the period. To do so, i have a first measure that gives what i expect :

TotalSalesByMonth =
CALCULATE(
    SUM('Sales'[Sales EUR]),
    ALLEXCEPT('Sales', 'Sales'[ImpactedMonth])
)
Below the result in the table visual, the total sales of each month is repeated for each raw of the period. And it is the result i want to obtain
BrunoM_0-1727892899759.png

 

 

EXPECTED: I would like to obtain the same result with a measure based on a virtual table like the VAR _VirtualSalesTable below

 

TotalSalesByMonth (Virtual table) =
VAR _VirtualSalesTable = SELECTCOLUMNS(Sales,
        Sales[ImpactedMonth],
        Sales[SRK],
        Sales[Sales EUR] )


In advance thank you for your help

 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @BrunoM ,

 

Any result created when using a virtual table is intermediate and there is no way to directly “return” it, try the following expression:

TotalSalesByMonth = 
VAR _VirtualSalesTable = 
    SELECTCOLUMNS(
        Sales,
        "ImpactedMonth", Sales[ImpactedMonth],
        "SRK", Sales[SRK],
        "SalesEUR", Sales[Sales EUR]
    )
VAR _totalSales = 
    ADDCOLUMNS(
        _VirtualSalesTable,
        "Total", SUMX(
            FILTER(
                _VirtualSalesTable, 
                [ImpactedMonth] = EARLIER([ImpactedMonth])
            ), 
            [SalesEUR]
        )
    )
RETURN MAXX(_totalSales, [Total])

 

 Best regards,
Community Support Team_ Scott Chang

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @BrunoM ,

 

I made simple samples and you can check the results below:

vtianyichmsft_0-1727920555587.png

Measure = var _t = ADDCOLUMNS('Table',"Total",SUMX(FILTER(ALL('Table'),[ImpactedMonth]=EARLIER([ImpactedMonth])),[Sale EUR]))
RETURN MAXX(_t,[Total])

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

First of all, thanks to @Anonymous and @Jihwan_Kim for your answers. Unfortunatly, your solutions do not fit with my expectation and sorry if i was not enough clear in my description. Let me explain:
The measure i want to create must have this structure : 


TotalSalesByMonth (Virtual table) =
VAR _VirtualSalesTable = SELECTCOLUMNS(Sales,
        Sales[ImpactedMonth],
        Sales[SRK],
        Sales[Sales EUR] )
VAR _totalSales = Function ( _VirtualSalesTable, expressions)
Return _totalSales
 
My attempts to write the VAR _totalSales always failed because the DAX functions i used do not allow me to use a column the the virtual table _VirtualSalesTable.
A solution on this simple example will help me to finalyze a meausre more complex.

Anonymous
Not applicable

Hi @BrunoM ,

 

Any result created when using a virtual table is intermediate and there is no way to directly “return” it, try the following expression:

TotalSalesByMonth = 
VAR _VirtualSalesTable = 
    SELECTCOLUMNS(
        Sales,
        "ImpactedMonth", Sales[ImpactedMonth],
        "SRK", Sales[SRK],
        "SalesEUR", Sales[Sales EUR]
    )
VAR _totalSales = 
    ADDCOLUMNS(
        _VirtualSalesTable,
        "Total", SUMX(
            FILTER(
                _VirtualSalesTable, 
                [ImpactedMonth] = EARLIER([ImpactedMonth])
            ), 
            [SalesEUR]
        )
    )
RETURN MAXX(_totalSales, [Total])

 

 Best regards,
Community Support Team_ Scott Chang

Jihwan_Kim
Super User
Super User

Hi,

Please try to write something like below.

 

SELECTCOLUMNS(
        Sales,
        Sales[ImpactedMonth],
        Sales[SRK],
        Sales[Sales EUR],
        "@TotalSalesByMonth", CALCULATE(
            SUM('Sales'[Sales EUR]),
            ALLEXCEPT(
                'Sales',
                'Sales'[ImpactedMonth]
            )
        )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.