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
pawelj795
Post Prodigy
Post Prodigy

Properly group the date

Hi,

I have data like below.

image.png

Now, I want to create a visual which gonna show at Axis grouped date.
These groups would be respectively: 30+, 15-30, 8-14, 1-7, overdue.

Dates would depend on TODAY()'s date difference. 

Now, at Values I want to Count numbers of companies that belong to an appropriate group.

Companies cannot duplicate! -> I mean by that if the same company has a few different dates I want to show the earliest.

 

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @pawelj795 ,

If I got it correctly, you can follow these steps to try:

1. Create the first measure to calculate datediff:

 

Date diff =
DATEDIFF (
    CALCULATE ( MIN ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Company] ) ),
    TODAY (),
    DAY
)

 

2. Create a new table included '30+', '15-30', '8-14', '1-7', 'Overdue' columns, just enter data manually

3. Create the second measure to get the expected result:

 

Count =
VAR tab =
    SUMMARIZE (
        'Table',
        [Company],
        "Earliest_Date", MIN ( 'Table'[Date] ),
        "Datediff", [Date diff]
    )
VAR newtab =
    ADDCOLUMNS (
        tab,
        "1-7", IF ( [Date diff] >= 1 && [Date diff] <= 7, 1, 0 ),
        "8-14", IF ( [Date diff] >= 8 && [Date diff] <= 14, 1, 0 ),
        "15-30", IF ( [Date diff] >= 15 && [Date diff] <= 30, 1, 0 ),
        "30+", IF ( [Date diff] >= 30, 1, 0 ),
        "OverDue", IF ( [Date diff] < 1 || [Date diff] = BLANK (), 1, 0 )
    )
VAR _group =
    SELECTEDVALUE ( Test[Group] )
RETURN
    SWITCH (
        _group,
        "1-7", COUNTROWS ( FILTER ( newtab, [1-7] = 1 ) ),
        "8-14", COUNTROWS ( FILTER ( newtab, [8-14] = 1 ) ),
        "15-30", COUNTROWS ( FILTER ( newtab, [15-30] = 1 ) ),
        "30+", COUNTROWS ( FILTER ( newtab, [30+] = 1 ) ),
        "OverDue", COUNTROWS ( FILTER ( newtab, [OverDue] = 1 ) ),
        BLANK ()
    )
​

group result.png

 

Here is my sample file hope to help you, please try it: PBIX 

 

Best Regards,
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

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @pawelj795 ,

If I got it correctly, you can follow these steps to try:

1. Create the first measure to calculate datediff:

 

Date diff =
DATEDIFF (
    CALCULATE ( MIN ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Company] ) ),
    TODAY (),
    DAY
)

 

2. Create a new table included '30+', '15-30', '8-14', '1-7', 'Overdue' columns, just enter data manually

3. Create the second measure to get the expected result:

 

Count =
VAR tab =
    SUMMARIZE (
        'Table',
        [Company],
        "Earliest_Date", MIN ( 'Table'[Date] ),
        "Datediff", [Date diff]
    )
VAR newtab =
    ADDCOLUMNS (
        tab,
        "1-7", IF ( [Date diff] >= 1 && [Date diff] <= 7, 1, 0 ),
        "8-14", IF ( [Date diff] >= 8 && [Date diff] <= 14, 1, 0 ),
        "15-30", IF ( [Date diff] >= 15 && [Date diff] <= 30, 1, 0 ),
        "30+", IF ( [Date diff] >= 30, 1, 0 ),
        "OverDue", IF ( [Date diff] < 1 || [Date diff] = BLANK (), 1, 0 )
    )
VAR _group =
    SELECTEDVALUE ( Test[Group] )
RETURN
    SWITCH (
        _group,
        "1-7", COUNTROWS ( FILTER ( newtab, [1-7] = 1 ) ),
        "8-14", COUNTROWS ( FILTER ( newtab, [8-14] = 1 ) ),
        "15-30", COUNTROWS ( FILTER ( newtab, [15-30] = 1 ) ),
        "30+", COUNTROWS ( FILTER ( newtab, [30+] = 1 ) ),
        "OverDue", COUNTROWS ( FILTER ( newtab, [OverDue] = 1 ) ),
        BLANK ()
    )
​

group result.png

 

Here is my sample file hope to help you, please try it: PBIX 

 

Best Regards,
Yingjie Li

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

If you post sample data as text and expected result, can probably be more accurate, Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

But perhaps something along the lines of:

Measure = 

  VAR __Table = SUMMARIZE('Table',[Company],"Min_Date",MIN([Date]))

RETURN

  <Some calculation over __Table>


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