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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
MissBI_21
Helper II
Helper II

Sum of a column

I have two columns, SumLast12Months and SumLast12Months2YearsAgo. 

SumLast12Months gives me the sum of the spend of visitors in the last 12 months and  SumLast12Months2YearsAgo gives ,e the sum of the spend over 12 months, 2 years ago.

 

SumLast12Months =
CALCULATE(
    SUM('NRR Data'[Value]),
    DATESINPERIOD('Dates'[Date], DATEADD(LASTDATE('Dates'[Date]), 0, YEAR), -12, MONTH)
)

SumLast12Months2YearsAgo =
CALCULATE(
    SUM('NRR Data'[Value]),
    DATESINPERIOD('Dates'[Date], DATEADD(LASTDATE('Dates'[Date]), -1, YEAR), -12, MONTH)
)

What I'm trying to do is create a measure/column that calculates for everyone who visted two years ago, how much did they spend last year.

I have the following measure which displays the right information in the table however, the sum on the column is not correct:

TestLogic = IF([SumLast12Months2YearsAgo] > 0, [SumLast12Months], 0)

MissBI_21_0-1692003810466.png

 

3 REPLIES 3
Anonymous
Not applicable

Hi @MissBI_21 ,

 

You can create a new measure to place on the visual object to check if total is correct.

TestLogic = IF([SumLast12Months2YearsAgo] > 0, [SumLast12Months], 0)
Total_TestLogic = 
SUMX(
    SUMMARIZE(
        'Table',
        'Table'[ColumnName],//Your first column on the visual object (the column that determines the value of the measure that follows)
        "total",[TestLogic]
    ),
    [total]
)

Or:

Total_TestLogic = 
SUMX(VALUES('Table'[ColumnName]),[TestLogic]) 
//Your first column on the visual object (the column that determines the value of the measure that follows)

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Hi,

 

What do you mean by:

//Your first column on the visual object (the column that determines the value of the measure that follows)

Anonymous
Not applicable

Hi @MissBI_21 ,

 

Please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. Thank you.

 

Best Regards,

Neeko Tang

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

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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