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
Blaggy
Helper I
Helper I

DATESINPERIOD gives correct figure for quarter, but not the full year

I'm using DATESINPERIOD in DAX, and it is giving me the correct, expected answer for the quarter, but it gives the latest quarter's answer for the full year as well, and I'm not sure why.

 

Here is my DAX:

 

Test Calc =

 

        DIVIDE(

            CALCULATE (    

                SUM('Table’[Amount]),

                DATESINPERIOD (

                    'Calendar'[Date],                                              

                    MAXX(DATEADD('Calendar'[Date],-1,QUARTER),'Calendar'[Date]),    

                    -16,                                                            

                    QUARTER                                                        

                    )

            ),16,0

        )

 

I've also tried the DATESBETWEEN DAX, and it is doing the same thing, where I'm getting the right answer for the quarter, but it is using the last quarter as the full year answer as well.  

1 ACCEPTED SOLUTION

Not sure what happened to my original response, but I did want to note that I figured it out, looking into what you mentioned on why PBI doesn't alwasy sum things the way you expect.  

 

To the extent this could be helpful to others, this was the DAX that worked for me:

 

Test Calc =

    SUMX(VALUES('Calendar'[Fiscal Qtr]),

        DIVIDE(

            CALCULATE (    

                SUM('Table’[Amount]),

                DATESINPERIOD (

                    'Calendar'[Date],                                              

                    MAXX(DATEADD('Calendar'[Date],-1,QUARTER),'Calendar'[Date]),    

                    -16,                                                            

                    QUARTER                                                        

                    )

            ),16,0

        )

   )

View solution in original post

8 REPLIES 8
Blaggy
Helper I
Helper I

Will check out.  I guess it's not something overly apparent (and overly stupid on my part) based on what you see in my DAX... which, somewhat makes me feel better about asking the question!

 

Thanks - will check out your videos when I free-up.  Appreciate it.

Not sure what happened to my original response, but I did want to note that I figured it out, looking into what you mentioned on why PBI doesn't alwasy sum things the way you expect.  

 

To the extent this could be helpful to others, this was the DAX that worked for me:

 

Test Calc =

    SUMX(VALUES('Calendar'[Fiscal Qtr]),

        DIVIDE(

            CALCULATE (    

                SUM('Table’[Amount]),

                DATESINPERIOD (

                    'Calendar'[Date],                                              

                    MAXX(DATEADD('Calendar'[Date],-1,QUARTER),'Calendar'[Date]),    

                    -16,                                                            

                    QUARTER                                                        

                    )

            ),16,0

        )

   )

parry2k
Super User
Super User

@Blaggy 

Check the related videos on my YT channel that talk about the reason why you get incorrect total

 

Incorrect Total - Part 1

Incorrect Total - Part 2





Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Blaggy
Helper I
Helper I

Curious if @parry2k (or others) can provide any insight as to whether I'm not using the DATESINPERIOD logic correctly so that I get the right answer for the full year rather than just the quarterly figures.  Thanks!

parry2k
Super User
Super User

Sorry still not very clear, you need to share some data with an example of what your expected output is?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Does this help?  Below is the output.  Note how the matrix is showing the FYE total being the same as Q4.  Again, each quarter is calculating properly for each BU, but for whatever reason, Power BI is not adding-up the quarters to get to the full-year figure.

 

Blaggy_0-1695152349510.png

 

Blaggy
Helper I
Helper I

Thank you, @parry2k .  I have the Table with the Amounts with a date field that is linked to the Calendar table.  The calendar table has the logic for fiscal quarters and fiscal years.  So, the logic as written is providing the correct answer for the fiscal quarters, but when trying to show the fiscal year (e.g. in a matrix view), it is calculating the last quarter only, rather than calculating the answer for the full fiscal year.  

 

Does that help?

parry2k
Super User
Super User

@Blaggy because you have having max based on the calender table, you need to use different date for this, without knowing which quarter you want to show and what would be the logic, it is  hard to provide the solution.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
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.