Forum Discussion

JustinDoh1's avatar
JustinDoh1
Post Prodigy
4 years ago
Solved

Calculate function - filter

I am trying to understand this DAX code here.

 

DAYSINMONTH =
               day(calculate(
                                       ENDOFMONTH('Calendar'[Date]),
                                       Table1
                                    )
                       )
 

Why do we have Table1 here?

I thought extra line is for filter (or extra filters), but this is only table name.

 

There is a relationship between 'Calendar' table and 'Table1' table.

 

Update:

I have attached Pbix file for better illustration.

Sorry for confusions.

 

Thanks.

16 Replies

Replies have been turned off for this discussion
  • tamerj1's avatar
    tamerj1
    Community Champion

    CALCULATE filters are actually tables. As per your data model the Calendar table filters the Table1. But in the code you mentioned, Table1 filters the Caledar date column. 
    The difference is that without using Table1 as a filter the code will return all the dates in the Calendar table. While using when using Table1 as a filter then all the months that are missing from Table1 will return blank. It seems that the user does not want to see the number of days for those months. 

      • JustinDoh1's avatar
        JustinDoh1
        Post Prodigy

        CNENFRNL Sorry. I should have posted my follow up question to your response on other post. I guess the answer is "it's an explicit leveraging of Expanded Table in such statements". Thank you!

    • littlemojopuppy's avatar
      littlemojopuppy
      Community Champion

      tamerj1 this is not accurate.  The Calendar table would be filtered by any dates in filter context, which would in turn filter any dates in Table1.

       

      But the discussion is irrelevant because using CALCULATE is over-complicating the solution in the first place.  DAY(EOMONTH('Calendar'[Date], 0)) solves the problem.  More simply, ENDOFMONTH solves the problem.

      • CNENFRNL's avatar
        CNENFRNL
        Community Champion

        Funny discussion, I'm wondering whether you ever ask youself a simplest but fairly intuitive question, what's the point of existence of ENDOFMONTH since there already exists EOMONTH?

    • JustinDoh1's avatar
      JustinDoh1
      Post Prodigy

      littlemojopuppy 

      Table1 is a name of a table.

      I am getting error mesage.

       

       

      Update:
      I have updated the Pbix file, and bottom are illustrations of two cases:

       

      • littlemojopuppy's avatar
        littlemojopuppy
        Community Champion

        JustinDoh1  I assumed it was a table.  Whole thing seems unnecessary.

         

        I didn't use ENDOFMONTH.  I used EOMONTH (returns the last day of a month with offset by number of months).