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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
FotFly
Helper II
Helper II

Summarize virtual table

Hi all,

I have the following code that summarizes the existing table in my dataset and performs some calculations.

Then I want that second table to be summarized based on one column and then return the sum of a newly created column.

I think that the answer to my problem might be obvious but I cannot seem to figure it out.
Using the below expressions I get for each date the total Weighted Transactions for all dates while I would want that to be for each AsOfDate.

Here is how the dax expession looks like:

VAR Trans =
SUMMARIZE(
    Transactions,
    Transactions[EffectiveDate],
    Transactions[AsOfDate],
    Transactions[CashAmount $],
    "Weight",
        DIVIDE(
            DATEDIFF(Transactions[EffectiveDate], Transactions[AsOfDate],DAY),
            DATEDIFF(EOMONTH(Transactions[AsOfDate], -3),Transactions[AsOfDate],DAY)
        ),
    "WeightedTrans",
        DIVIDE(
            DATEDIFF(Transactions[EffectiveDate], Transactions[AsOfDate],DAY),
            DATEDIFF(EOMONTH(Transactions[AsOfDate], -3),Transactions[AsOfDate],DAY)
        ) * [CashAmount $]
)



VAR SumWeightTrans =
SUMMARIZE(
    Trans,
    [AsOfDate],
    "SumWeightedTrans",
    SUMX(
        Trans,
        [WeightedTrans]
    )
)
RETURN
SumWeightReturns

Thanks in advance for your help.

2 ACCEPTED SOLUTIONS
rajendraongole1
Super User
Super User

Hi @FotFly - your DAX expression to ensure the grouping within the SUMMARIZE is scoped correctly

 

Modified the dax as below:

VAR Trans =
ADDCOLUMNS(
Transactions,
"Weight",
DIVIDE(
DATEDIFF(Transactions[EffectiveDate], Transactions[AsOfDate], DAY),
DATEDIFF(EOMONTH(Transactions[AsOfDate], -3), Transactions[AsOfDate], DAY)
),
"WeightedTrans",
DIVIDE(
DATEDIFF(Transactions[EffectiveDate], Transactions[AsOfDate], DAY),
DATEDIFF(EOMONTH(Transactions[AsOfDate], -3), Transactions[AsOfDate], DAY)
) * Transactions[CashAmount $]
)

VAR SumWeightTrans =
SUMMARIZE(
Trans,
Trans[AsOfDate],
"SumWeightedTrans",
SUMX(
FILTER(Trans, Trans[AsOfDate] = EARLIER(Trans[AsOfDate])),
[WeightedTrans]
)
)

RETURN
SumWeightTrans

 

I hope this result in the correct sum of WeightedTrans grouped by AsOfDate.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

johnt75
Super User
Super User

Try

SummaryTable =
VAR Trans =
    ADDCOLUMNS (
        SUMMARIZE ( Transactions, Transactions[EffectiveDate], Transactions[AsOfDate] ),
        "@Cash Amount $", CALCULATE ( SUM ( Transactions[CashAmount $] ) ),
        "@WeightedTrans",
            DIVIDE (
                DATEDIFF ( Transactions[EffectiveDate], Transactions[AsOfDate], DAY ),
                DATEDIFF ( EOMONTH ( Transactions[AsOfDate], -3 ), Transactions[AsOfDate], DAY )
            ) * [@CashAmount $]
    )
VAR SumWeightTrans =
    GROUPBY (
        Trans,
        [AsOfDate],
        "@SumWeightedTrans", SUMX ( CURRENTGROUP (), [@WeightedTrans] )
    )
RETURN
    SumWeightReturns

The main point is to use GROUPBY rather than the second SUMMARIZE, but I've also tweaked the code a bit.

You should never use SUMMARIZE to add calculated columns, just use that for grouping and use ADDCOLUMNS to add the new columns you need.

I've also removed the Weight column as it wasn't being used, so there's no point calculating it.

Finally, I use @ in column names in temporary tables, so that they are easily distinguishable from columns or measures in the model.

View solution in original post

5 REPLIES 5
Kedar_Pande
Super User
Super User

@FotFly 

Here’s the corrected DAX expression:

VAR Trans =
SUMMARIZE(
Transactions,
Transactions[EffectiveDate],
Transactions[AsOfDate],
Transactions[CashAmount $],
"Weight",
DIVIDE(
DATEDIFF(Transactions[EffectiveDate], Transactions[AsOfDate], DAY),
DATEDIFF(EOMONTH(Transactions[AsOfDate], -3), Transactions[AsOfDate], DAY)
),
"WeightedTrans",
DIVIDE(
DATEDIFF(Transactions[EffectiveDate], Transactions[AsOfDate], DAY),
DATEDIFF(EOMONTH(Transactions[AsOfDate], -3), Transactions[AsOfDate], DAY)
) * Transactions[CashAmount $]
)

VAR SumWeightTrans =
SUMMARIZE(
Trans,
[AsOfDate],
"SumWeightedTrans",
SUMX(
CURRENTGROUP(), -- Use CURRENTGROUP() to reference the rows within each AsOfDate group
[WeightedTrans]
)
)

RETURN
SumWeightTrans

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

 

johnt75
Super User
Super User

Try

SummaryTable =
VAR Trans =
    ADDCOLUMNS (
        SUMMARIZE ( Transactions, Transactions[EffectiveDate], Transactions[AsOfDate] ),
        "@Cash Amount $", CALCULATE ( SUM ( Transactions[CashAmount $] ) ),
        "@WeightedTrans",
            DIVIDE (
                DATEDIFF ( Transactions[EffectiveDate], Transactions[AsOfDate], DAY ),
                DATEDIFF ( EOMONTH ( Transactions[AsOfDate], -3 ), Transactions[AsOfDate], DAY )
            ) * [@CashAmount $]
    )
VAR SumWeightTrans =
    GROUPBY (
        Trans,
        [AsOfDate],
        "@SumWeightedTrans", SUMX ( CURRENTGROUP (), [@WeightedTrans] )
    )
RETURN
    SumWeightReturns

The main point is to use GROUPBY rather than the second SUMMARIZE, but I've also tweaked the code a bit.

You should never use SUMMARIZE to add calculated columns, just use that for grouping and use ADDCOLUMNS to add the new columns you need.

I've also removed the Weight column as it wasn't being used, so there's no point calculating it.

Finally, I use @ in column names in temporary tables, so that they are easily distinguishable from columns or measures in the model.

Thank you very much! I will test is out. This is a different approach that I havent thought.

rajendraongole1
Super User
Super User

Hi @FotFly - your DAX expression to ensure the grouping within the SUMMARIZE is scoped correctly

 

Modified the dax as below:

VAR Trans =
ADDCOLUMNS(
Transactions,
"Weight",
DIVIDE(
DATEDIFF(Transactions[EffectiveDate], Transactions[AsOfDate], DAY),
DATEDIFF(EOMONTH(Transactions[AsOfDate], -3), Transactions[AsOfDate], DAY)
),
"WeightedTrans",
DIVIDE(
DATEDIFF(Transactions[EffectiveDate], Transactions[AsOfDate], DAY),
DATEDIFF(EOMONTH(Transactions[AsOfDate], -3), Transactions[AsOfDate], DAY)
) * Transactions[CashAmount $]
)

VAR SumWeightTrans =
SUMMARIZE(
Trans,
Trans[AsOfDate],
"SumWeightedTrans",
SUMX(
FILTER(Trans, Trans[AsOfDate] = EARLIER(Trans[AsOfDate])),
[WeightedTrans]
)
)

RETURN
SumWeightTrans

 

I hope this result in the correct sum of WeightedTrans grouped by AsOfDate.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank you very much!

I tried that version with filter before but it was the earlier part that I was missing. I was trying to find an expression that could actually function with my virtual table column while filtering.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.