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
dollaratneu
New Member

Getting percentage count by days

I've a dataset as under:

datedays
2020-01-15 12:131
2020-01-15 10:481
2020-01-15 10:452
2020-01-15 9:513
2020-01-15 9:523
2020-01-15 9:075
2020-01-15 11:432
2020-01-15 12:467
2020-01-15 13:122
2020-01-15 9:582
2020-01-15 11:292
2020-01-15 10:382
2020-01-15 11:212
2020-01-15 12:422
2020-01-15 14:322
2020-01-15 10:492
2020-01-15 15:332
2020-01-15 11:322
2020-01-15 10:502


I'm having a hard time to create a new table which would show the percentage of days where days<2 and percent of days where days >= 2

so the resulting table would look like this:


MonthDays%
Jan-20<210
Jan-20>299
Feb-20<220
Feb-20>280
1 ACCEPTED SOLUTION

Hi @dollaratneu ,

Based on your description, you can create a new calculated table like this:

New Table = 
VAR t1 =
    ADDCOLUMNS (
        'Table',
        "Month Days",
            SWITCH (
                TRUE (),
                'Table'[date].[MonthNo] = 1
                    && 'Table'[date].[Day] >= 1
                    && 'Table'[date].[Day] < 20, "Jan-20 <2",
                'Table'[date].[MonthNo] = 1
                    && 'Table'[date].[Day] >= 20
                    && 'Table'[date].[Day] <= 31, "Jan-20 >2",
                'Table'[date].[MonthNo] = 2
                    && 'Table'[date].[Day] >= 1
                    && 'Table'[date].[Day] < 20, "Feb-20 <2",
                'Table'[date].[MonthNo] = 2
                    && 'Table'[date].[Day] >= 20
                    && 'Table'[date].[Day] <= 29, "Feb-20 >2"
            ),
        "Total Count",
            CALCULATE (
                COUNT ( 'Table'[date] ),
                ALLEXCEPT ( 'Table', 'Table'[date].[MonthNo] )
            )
    )
VAR t2 =
    ADDCOLUMNS (
        t1,
        "Count",
            SWITCH (
                TRUE (),
                [days] < 2
                    && [Month Days] = "Jan-20 <2",
                    COUNTX ( FILTER ( t1, [days] < 2 && [Month Days] = "Jan-20 <2" ), [date] ),
                [days] >= 2
                    && [Month Days] = "Jan-20 >2",
                    COUNTX ( FILTER ( t1, [days] >= 2 && [Month Days] = "Jan-20 >2" ), [date] ),
                [days] < 2
                    && [Month Days] = "Feb-20 <2",
                    COUNTX ( FILTER ( t1, [days] < 2 && [Month Days] = "Feb-20 <2" ), [date] ),
                [days] >= 2
                    && [Month Days] = "Feb-20 >2",
                    COUNTX ( FILTER ( t1, [days] >= 2 && [Month Days] = "Feb-20 >2" ), [date] )
            )
    )
RETURN
    SUMMARIZE (
        SUMMARIZE (
            FILTER ( t2, [Count] <> BLANK () ),
            [Month Days],
            [Total Count],
            [Count],
            "%", [Count] / [Total Count]
        ),
        [Month Days],
        [%]
    )

re.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
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

3 REPLIES 3
parry2k
Super User
Super User

@dollaratneu sorry not fully clear what you are looking for, can you provide but more details.



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.

sure !

what I'm trying to do here is, get the percent of count of days for each month where the "days" column is less than 2 and likewise get the percent of count of days for each month where the "days" column is less than or equal to 2

Hi @dollaratneu ,

Based on your description, you can create a new calculated table like this:

New Table = 
VAR t1 =
    ADDCOLUMNS (
        'Table',
        "Month Days",
            SWITCH (
                TRUE (),
                'Table'[date].[MonthNo] = 1
                    && 'Table'[date].[Day] >= 1
                    && 'Table'[date].[Day] < 20, "Jan-20 <2",
                'Table'[date].[MonthNo] = 1
                    && 'Table'[date].[Day] >= 20
                    && 'Table'[date].[Day] <= 31, "Jan-20 >2",
                'Table'[date].[MonthNo] = 2
                    && 'Table'[date].[Day] >= 1
                    && 'Table'[date].[Day] < 20, "Feb-20 <2",
                'Table'[date].[MonthNo] = 2
                    && 'Table'[date].[Day] >= 20
                    && 'Table'[date].[Day] <= 29, "Feb-20 >2"
            ),
        "Total Count",
            CALCULATE (
                COUNT ( 'Table'[date] ),
                ALLEXCEPT ( 'Table', 'Table'[date].[MonthNo] )
            )
    )
VAR t2 =
    ADDCOLUMNS (
        t1,
        "Count",
            SWITCH (
                TRUE (),
                [days] < 2
                    && [Month Days] = "Jan-20 <2",
                    COUNTX ( FILTER ( t1, [days] < 2 && [Month Days] = "Jan-20 <2" ), [date] ),
                [days] >= 2
                    && [Month Days] = "Jan-20 >2",
                    COUNTX ( FILTER ( t1, [days] >= 2 && [Month Days] = "Jan-20 >2" ), [date] ),
                [days] < 2
                    && [Month Days] = "Feb-20 <2",
                    COUNTX ( FILTER ( t1, [days] < 2 && [Month Days] = "Feb-20 <2" ), [date] ),
                [days] >= 2
                    && [Month Days] = "Feb-20 >2",
                    COUNTX ( FILTER ( t1, [days] >= 2 && [Month Days] = "Feb-20 >2" ), [date] )
            )
    )
RETURN
    SUMMARIZE (
        SUMMARIZE (
            FILTER ( t2, [Count] <> BLANK () ),
            [Month Days],
            [Total Count],
            [Count],
            "%", [Count] / [Total Count]
        ),
        [Month Days],
        [%]
    )

re.png

Attached a sample file in the below, hopes to help you.

 

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

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.