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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
RavenQueen0311
Frequent Visitor

Calculated Column Doesn't work for current year only

I'm new to Power BI, and trying to learn quickly, but I'm scratching my head at this issue.  I also know this might not be the best way to accomplish what I'm trying to accomplish, so feel free to suggest alternatives.

 

I have a table of data rolled up by a few factors, include the Date, State, and a couple of other fields.  In each row there is a column called OpenAccounts representing the number of accounts that were in an Open Status on that date from that state, etc.

 

I have been tasked with creating a year over year comparison where the user can select the date to run the compairson for.  For this field, since the OpenAccounts is the number of accounts already open at a given point of time, I can't add up YTD.  I have to find the records that match the Date being selected.  In order to select that date, a request has been made to use a sliding date slicer, rather than a dropdown. I opted to use a Before Date Slicer.

 

In order to accomplish this, I created a measure to find the Max selected date:

 

 

 

ThisYearEndDate = MAXX(ALLSELECTED(QBR_DAILYTOTALS[TRANSACTIONDATEPST]), QBR_DAILYTOTALS[TRANSACTIONDATEPST])

 

 

 

 

This seems to work fine.  So then using this measure, I am trying to get the sum of values where the Month and Day of the TransactionDatePST field match the Month and Day of ThisYearEndDate.  After trying a bunch of different ways to do this, I settled on creating a calculated column as follows:

 

 

 

Open Accounts = IF(
    AND(
        MONTH(QBR_DAILYTOTALS[TRANSACTIONDATEPST]) = MONTH(QBR_DAILYTOTALS[ThisYearEndDate]),
        DAY(QBR_DAILYTOTALS[TRANSACTIONDATEPST]) = DAY(QBR_DAILYTOTALS[ThisYearEndDate])
    ),
    QBR_DAILYTOTALS[OPENACCOUNTS],
    0
)

 

 

 

 

Then I grab the SUM of that for all the open accounts on a given date.  This works for all Previous Years (2020, 2021) but always returns 0 for 2022.  I cannot for the life of me figure out why.

 

For Instance, if I have my Date Slicer to 4/1/2022, the numbers are correct for 2020 & 2021, but 2022 returns 0:

RavenQueen0311_0-1651252449759.png

 

As you can see, doing a simple sum of OPENACCOUNTS for that day shows there are values, but the calculated field always sets it to 0.

 

Does anyone know what is going on here?  Or have a better solution for my issue?

 

Example Data:

TRANSACTIONDATEPSTSTATEPROVINCEOPENACCOUNTS
4/1/2020AZ784
4/1/2020NV11,167
4/2/2020NV11,174
4/2/2020AZ784
4/3/2020NV11,181
4/3/2020AZ789
4/1/2021AZ1,451
4/1/2021NV17,140
4/2/2021NV17,170
4/2/2021AZ1,455
4/3/2021AZ1,461
4/3/2021NV17,209
4/1/2022AZ13,062
4/1/2022NV27,288
4/2/2022AZ13,087
4/2/2022NV27,323
4/3/2022NV27,342
4/3/2022AZ13,114
1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @RavenQueen0311 ,

 

In your scenario, [ThisYearEndDate] is a measure and [Open Accounts] is a calculated column. Then, the  value of [ThisYearEndDate] will be static when used in [Open Accounts]. The result is always "4/3/2022". The value of calculated column won't change dynamically based on a slicer. 

Icey_0-1651546393708.png

 

Then you can find that, on 4/1/2022, the result is FALSE. So it returns 0.

Icey_1-1651546581020.png

 

Try to create a measure like so:

Open Accounts Measure = 
CALCULATE (
    SUM ( QBR_DAILYTOTALS[OPENACCOUNTS] ),
    FILTER (
        ALLSELECTED ( QBR_DAILYTOTALS[TRANSACTIONDATEPST] ),
        AND (
            MONTH ( QBR_DAILYTOTALS[TRANSACTIONDATEPST] )
                = MONTH ( QBR_DAILYTOTALS[ThisYearEndDate] ),
            DAY ( QBR_DAILYTOTALS[TRANSACTIONDATEPST] )
                = DAY ( QBR_DAILYTOTALS[ThisYearEndDate] )
        )
    )
)

Icey_0-1651554691457.png

Icey_1-1651554737587.png

For more details, check the attachment.

 

 

 

Best Regards,

Icey

 

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

 

 

View solution in original post

2 REPLIES 2
Icey
Community Support
Community Support

Hi @RavenQueen0311 ,

 

In your scenario, [ThisYearEndDate] is a measure and [Open Accounts] is a calculated column. Then, the  value of [ThisYearEndDate] will be static when used in [Open Accounts]. The result is always "4/3/2022". The value of calculated column won't change dynamically based on a slicer. 

Icey_0-1651546393708.png

 

Then you can find that, on 4/1/2022, the result is FALSE. So it returns 0.

Icey_1-1651546581020.png

 

Try to create a measure like so:

Open Accounts Measure = 
CALCULATE (
    SUM ( QBR_DAILYTOTALS[OPENACCOUNTS] ),
    FILTER (
        ALLSELECTED ( QBR_DAILYTOTALS[TRANSACTIONDATEPST] ),
        AND (
            MONTH ( QBR_DAILYTOTALS[TRANSACTIONDATEPST] )
                = MONTH ( QBR_DAILYTOTALS[ThisYearEndDate] ),
            DAY ( QBR_DAILYTOTALS[TRANSACTIONDATEPST] )
                = DAY ( QBR_DAILYTOTALS[ThisYearEndDate] )
        )
    )
)

Icey_0-1651554691457.png

Icey_1-1651554737587.png

For more details, check the attachment.

 

 

 

Best Regards,

Icey

 

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

 

 

Fantastic!  Thank you so much for the explanation, Icey.  I've tried your suggestion and it looks to be working.  You've saved me from a terrible fate, haha.

 

Appreciated!

 

Raven

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.