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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
v-tangjie-msft
Community Support
Community Support

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)

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors