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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
sarochch
Frequent Visitor

How to count same ID current month and next month

 

Hi all,

 

I have a table and want to create summary table like example below. 

 

example: (Column G)

Report Jan-18 : count all ID (Jan18) in Feb-18 which no. of day >30

Report Feb-18: count all ID (Feb18) in Mar-18 which no. of day >30

Each month no duplicate ID.

 

How to use DAX or another way to solve it ?

 

Thank you

 

 

Untitled.jpg

 

 

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @sarochch,

 

Suppose the source data table is called 'Tab_3', please refer to below DAX to generate a calculated table:

Tab_4 =
SUMMARIZE (
    Tab_3,
    Tab_3[Date],
    "No. of day >=8", CALCULATE ( COUNT ( Tab_3[ID] ), Tab_3[No.of day] >= 8 ),
    "No. of day >30 next month", COUNTROWS (
        INTERSECT (
            VALUES ( Tab_3[ID] ),
            CALCULATETABLE (
                VALUES ( Tab_3[ID] ),
                FILTER (
                    ALL ( Tab_3 ),
                    Tab_3[No.of day] > 30
                        && YEAR ( Tab_3[Date] ) = YEAR ( EARLIER ( Tab_3[Date] ) )
                        && MONTH ( Tab_3[Date] )
                            = MONTH ( EARLIER ( Tab_3[Date] ) ) + 1
                )
            )
        )
    )
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

1 REPLY 1
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @sarochch,

 

Suppose the source data table is called 'Tab_3', please refer to below DAX to generate a calculated table:

Tab_4 =
SUMMARIZE (
    Tab_3,
    Tab_3[Date],
    "No. of day >=8", CALCULATE ( COUNT ( Tab_3[ID] ), Tab_3[No.of day] >= 8 ),
    "No. of day >30 next month", COUNTROWS (
        INTERSECT (
            VALUES ( Tab_3[ID] ),
            CALCULATETABLE (
                VALUES ( Tab_3[ID] ),
                FILTER (
                    ALL ( Tab_3 ),
                    Tab_3[No.of day] > 30
                        && YEAR ( Tab_3[Date] ) = YEAR ( EARLIER ( Tab_3[Date] ) )
                        && MONTH ( Tab_3[Date] )
                            = MONTH ( EARLIER ( Tab_3[Date] ) ) + 1
                )
            )
        )
    )
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.

Top Kudoed Authors