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

DAX Count Number of Days in a given month from a date dimension where other table condition meet

Hi there 

I need help with DAX.

 

Have below two tables :

    Calendar_Dimension_Table

       The_Date       Year     Month

       2020-08-15   2020   August

       2020-08-16   2020   August

       2020-08-17   2020   August

       .............

       .............

 

     Sales_Table

       Sales_Date     Sales_Item   Sales_Status   Sales_Category

       2020-08-15     IT123           OPEN               MAJOR

       2020-08-15     ITYYY           OPEN               MAJOR

       2020-08-15     IT876           CLOSED            MINOR

       2020-08-15     IT876           SUBMIT            MINOR

       2020-08-15     IT876           PROCESS          MINOR

       2020-08-16     IT123           CLOSED            MAJOR

       2020-08-17     ITABC           OPEN               MAJOR

       2020-08-17     ITXYZ            OPEN               MAJOR

       .............

       .............

 

Tables are join with The_Date and Sales_Date columns.

 

I am after DAX  that provide number of days per calender month where sales status is not closed or sales category is minor.

     Expected output is 2 days for Auguest (because 15th Aug and 17th Aug)

 

Many Thanks.

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Measure = 
CALCULATE(
    DISTINCTCOUNT( SALES[Sales_Date] ),
    FILTER(
        SUMMARIZE( SALES, SALES[Sales_Date], SALES[Sales_Item] ),
        CALCULATE(
            NOT ISEMPTY( SALES ),
            SALES[Sales_Status] <> "Closed"
                || SALES[Sales_Status] = "Minor"
        )
    )
)

Screenshot 2021-09-08 040632.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

Measure = 
CALCULATE(
    DISTINCTCOUNT( SALES[Sales_Date] ),
    FILTER(
        SUMMARIZE( SALES, SALES[Sales_Date], SALES[Sales_Item] ),
        CALCULATE(
            NOT ISEMPTY( SALES ),
            SALES[Sales_Status] <> "Closed"
                || SALES[Sales_Status] = "Minor"
        )
    )
)

Screenshot 2021-09-08 040632.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Not really. COUNTROWS does not give distinct number of days in a month where condition meet (per my original post requirement). Any idea pls

@kaushikmakadia So then this:

Measure = 
  COUNTROWS(
    DISTINCT(
      SELECTCOLUMNS(
        FILTER('Sales_Table',[Sales_Status]="OPEN" && [Sales_Category]="MINOR")
        "Date",[Sales_Date]
      )
    )
  )

Try not to cross-post please.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@kaushikmakadia Try:

Measure = COUNTROWS(FILTER('Sales_Table',[Sales_Status]="OPEN" && [Sales_Category]="MINOR"))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.