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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

DAX

Hi All,
I have data like below, Duplicates of drw-No, if release date is null, No of days = 0,  if minnimum release date of draw_no having date, No of days  = release date - previous date of release date, if previous date of release date null, No of days = release date- previous date of revision date.

S.NoDraw_NoRevRevision DateRelease dateNo of daysexplanation
10001A12/01/2023null0Release date = null, 0
20001B18/01/202312/02/202328 12/02/2023 - 12/01/2023
30001C19/02/202312/03/20233012/03/2023- 12/02/2023
40002D1/03/202319/04/20230 
50002E 1/05/2023111/05/2023 - 19/04/2023
60002F 12/05/20231212/05/2023 - 1/05/2023
 0001G 12/06/20239012/06/2023 - 12/03/2023

 

How can I write dax formula to get above result, please support me if any know the solution.


Thanks,
Maneesha.

1 ACCEPTED SOLUTION
Daniel29195
Community Champion
Community Champion

 

Hello @Anonymous ,

can you please check if this is what you want  : 

Daniel29195_0-1705663863519.png

 

 

Daniel29195_1-1705663878862.png

 

 

nb of days =
VAR draw_nb =  'Table (16)'[Draw_No]

var datasource =
FILTER(
        SUMMARIZE(
            'Table (16)',
            'Table (16)'[Draw_No],
            'Table (16)'[Release date]
        ),
        'Table (16)'[Draw_No] = draw_nb
    )

var min_release_date =
    MINX(
        datasource ,
        'Table (16)'[Release date]
    )

var prev_date_of_release_date =
SELECTCOLUMNS(
OFFSET(
    -1,
    datasource,
    ORDERBY('Table (16)'[Release date] , asc )
),
"@prev_release_date",'Table (16)'[Release date]
)


var prev_date_of_revision_date =
SELECTCOLUMNS(
OFFSET(
    -1,
    datasource,
    ORDERBY('Table (16)'[Release date] , asc )
),
"@prev_rev_date",'Table (16)'[Revision Date]
)


RETURN
SWITCH(
    TRUE(),
    'Table (16)'[Release date] = "null" || ISBLANK('Table (16)'[Release date]) , 0 ,
    not ISBLANK(min_release_date) , 'Table (16)'[Release date] - prev_date_of_release_date,
     ISBLANK(prev_date_of_release_date), 'Table (16)'[Release date] - prev_date_of_revision_date
)
   
let me know if you have any problem or concerns,  i would be happy to help you out. 

best regards, 


View solution in original post

1 REPLY 1
Daniel29195
Community Champion
Community Champion

 

Hello @Anonymous ,

can you please check if this is what you want  : 

Daniel29195_0-1705663863519.png

 

 

Daniel29195_1-1705663878862.png

 

 

nb of days =
VAR draw_nb =  'Table (16)'[Draw_No]

var datasource =
FILTER(
        SUMMARIZE(
            'Table (16)',
            'Table (16)'[Draw_No],
            'Table (16)'[Release date]
        ),
        'Table (16)'[Draw_No] = draw_nb
    )

var min_release_date =
    MINX(
        datasource ,
        'Table (16)'[Release date]
    )

var prev_date_of_release_date =
SELECTCOLUMNS(
OFFSET(
    -1,
    datasource,
    ORDERBY('Table (16)'[Release date] , asc )
),
"@prev_release_date",'Table (16)'[Release date]
)


var prev_date_of_revision_date =
SELECTCOLUMNS(
OFFSET(
    -1,
    datasource,
    ORDERBY('Table (16)'[Release date] , asc )
),
"@prev_rev_date",'Table (16)'[Revision Date]
)


RETURN
SWITCH(
    TRUE(),
    'Table (16)'[Release date] = "null" || ISBLANK('Table (16)'[Release date]) , 0 ,
    not ISBLANK(min_release_date) , 'Table (16)'[Release date] - prev_date_of_release_date,
     ISBLANK(prev_date_of_release_date), 'Table (16)'[Release date] - prev_date_of_revision_date
)
   
let me know if you have any problem or concerns,  i would be happy to help you out. 

best regards, 


Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors