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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Jeevan1991
Helper III
Helper III

Difference Between First Bill, Second Bill & Last Bill

Dear Friends,

 

I want a help on below data.

I am having a data like the below one.

DateMobile #Bill #Bill Time
27-Jan-2021974324732354616:38:36
27-Jan-2021974324732357817:48:55
27-Jan-2021974324732358821:38:36
27-Jan-2021645654765754313:38:36
27-Jan-2021675676588645410:38:36
27-Jan-2021745657566674611:38:36
27-Jan-2021564575467675517:38:36
27-Jan-2021564575467680018:38:36
27-Jan-2021564575467687620:38:36
28-Jan-2021974324732354617:38:36
28-Jan-2021974324732357817:38:36
28-Jan-2021974324732358821:38:36
28-Jan-2021645654765754315:38:36
28-Jan-2021675676588645400:38:36
28-Jan-2021745657566674609:38:36
28-Jan-2021564575467675517:48:36
28-Jan-2021564575467680020:38:36
28-Jan-2021564575467687621:58:36

 

Now i want to find the bill time difference between first bill time, second bill time and last bill time and so on based on mobile numbers.

 

Please help me on DAX to find the table like the below one and the result column is "Bill Time Difference".

 

DateMobile #Bill #Bill TimeBill Time Difference
27-Jan-2021974324732354616:38:36First Bill
27-Jan-2021974324732357817:48:5501:10:19
27-Jan-2021974324732358821:38:3605:00:00
27-Jan-2021645654765754313:38:36First Bill
27-Jan-2021675676588645410:38:36First Bill
27-Jan-2021745657566674611:38:36First Bill
27-Jan-2021564575467675517:38:36First Bill
27-Jan-2021564575467680018:38:3601:00:00
27-Jan-2021564575467687620:38:3603:00:00
28-Jan-2021974324732354617:38:36First Bill
28-Jan-2021974324732357817:38:3600:00:00
28-Jan-2021974324732358821:38:3604:00:00
28-Jan-2021645654765754315:38:36First Bill
28-Jan-2021675676588645400:38:36First Bill
28-Jan-2021745657566674609:38:36First Bill
28-Jan-2021564575467675517:48:36First Bill
28-Jan-2021564575467680020:38:3602:50:00
28-Jan-2021564575467687621:58:3604:10:00

@v-easonf-msft @speedramps @amitchandak

1 ACCEPTED SOLUTION
Geradav
Responsive Resident
Responsive Resident

@Jeevan1991 

 

If you were to use DAX and a calculated column here below is the DAX you could use:


TimeDiff =
VAR mobileNum = [Mobile #]
VAR billDate = [Date]
VAR billTime = [Bill Time]
VAR firstBillTime =
    CALCULATE (
        MIN ( [Bill Time] ),
        FILTER (
            TableBills,
            TableBills[Mobile #] = mobileNum
                && TableBills[Date] = billDate
        )
    )
RETURN
    IF ( firstBillTime = billTimeTIME ( 000 )billTime - firstBillTime )


However, passing by Power Query might be a better approach to add a column

 

Let us know if that works for you

 

David

View solution in original post

3 REPLIES 3
Geradav
Responsive Resident
Responsive Resident

@Jeevan1991 

 

If you were to use DAX and a calculated column here below is the DAX you could use:


TimeDiff =
VAR mobileNum = [Mobile #]
VAR billDate = [Date]
VAR billTime = [Bill Time]
VAR firstBillTime =
    CALCULATE (
        MIN ( [Bill Time] ),
        FILTER (
            TableBills,
            TableBills[Mobile #] = mobileNum
                && TableBills[Date] = billDate
        )
    )
RETURN
    IF ( firstBillTime = billTimeTIME ( 000 )billTime - firstBillTime )


However, passing by Power Query might be a better approach to add a column

 

Let us know if that works for you

 

David

It is working bro.

 

Thank you so much for your time and effort.

In case of any additional requirement i will get back to you.

amitchandak
Super User
Super User

@Jeevan1991 , You can create a rank columns like these

 

rank = rankx(filter(Table, [Mobile #] =earlier([Mobile #])) ,[Bill #],,asc)

date time = [date]+ [time]
time diff as column = [date time] = maxx(filter(Table, [Mobile #] =earlier([Mobile #]) && [date time] <earlier([date time])),[date time])
or
time diff as column = [date time] = maxx(filter(Table, [Mobile #] =earlier([Mobile #]) && [Rank] <earlier([Rank])),[date time])

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.