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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
sugloevg
Frequent Visitor

CALCULATE returns blank values

Hi!

 

I have a simple measure but i can't get why it doesnt work.

 

For example i have table:

YearLSV
20181235
20195432
20207653

 

So i need to show value by the previous year in a row. I made the following measure:

PREVLSV = CALCULATE(SUM('Table'[LSV]), FILTER('Table', 'Table'[Year] = [Year]-1))
 
and it returns blank values for all rows:
 

image.png

 

Is there ant chance to get it works?

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @sugloevg 

Measure has no real sense with just a [Year] in filter sentence

try

PREVLSV = 
var _curYear = MAX('Table'[Year])
RETURN
CALCULATE(SUM('Table'[LSV]), FILTER(ALL('Table'), 'Table'[Year] = _curYear -1))

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

8 REPLIES 8
Syndicate_Admin
Administrator
Administrator

Try this @sugloevg

Prior Year = 
VAR PriorYear = MAX('Table'[Year]) - 1
VAR Result = 
    SUMX(
        FILTER(
            ALL('Table'),
            'Table'[Year] = PriorYear
        ),
        'Table'[LSV]
    )
RETURN
    Result

Gets the current year, and then subtracts 1. Then, the SUMX() only works on the previous year's data from the table provided by FILTER().

2020-05-10 09_38_46-Untitled - Power BI Desktop.png

Syndicate_Admin
Administrator
Administrator

Try this @sugloevg

Prior Year = 
VAR PriorYear = MAX('Table'[Year]) - 1
VAR Result = 
    SUMX(
        FILTER(
            ALL('Table'),
            'Table'[Year] = PriorYear
        ),
        'Table'[LSV]
    )
RETURN
    Result

Gets the current year, and then subtracts 1. Then, the SUMX() only works on the previous year's data from the table provided by FILTER().

2020-05-10 09_38_46-Untitled - Power BI Desktop.png

sugloevg
Frequent Visitor

Thank you a lot, guys!

edhans
Super User
Super User

Try this @sugloevg 

Prior Year = 
VAR PriorYear = MAX('Table'[Year]) - 1
VAR Result = 
    SUMX(
        FILTER(
            ALL('Table'),
            'Table'[Year] = PriorYear
        ),
        'Table'[LSV]
    )
RETURN
    Result

It gets the current year, then subtracts 1. Then the SUMX() only operates on prior year data from the table provided by FILTER().

2020-05-10 09_38_46-Untitled - Power BI Desktop.png



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
nandukrishnavs
Super User
Super User

@sugloevg 

Try this DAX measure

 

 

PREVLSV =
VAR _Year =
    SELECTEDVALUE ( 'Table'[Year] )
RETURN
    CALCULATE (
        SUM ( 'Table'[LSV] ),
        FILTER ( ALL ( 'Table'[Year] ), 'Table'[Year] = _Year - 1 )
    )

 

 

Capture.JPG



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂 


Regards,
Nandu Krishna

az38
Community Champion
Community Champion

Hi @sugloevg 

Measure has no real sense with just a [Year] in filter sentence

try

PREVLSV = 
var _curYear = MAX('Table'[Year])
RETURN
CALCULATE(SUM('Table'[LSV]), FILTER(ALL('Table'), 'Table'[Year] = _curYear -1))

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Osama14
Frequent Visitor

Hi @az38 

I have used your formula but what if I want to get the month breakdown?  It's showing the total sum but I know it's because of the Calculate Sum but don't know How to get month breakdown 

Osama14_0-1636269013365.png

 

az38
Community Champion
Community Champion

Hi @Osama14 

you can try SAMEPERIODLASTYEAR() function.

like

CALCULATE(SUM('Table'[LSV]), SAMEPERIODLASTYEAR('Table'[Date]))

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.