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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Maya2988
Helper I
Helper I

Need help in creating Date Difference in Power BI

Hi All,

 

I amtrying to create a power bi reporte using SQL Server Direct Query mode. I have the below columns with some sample values

 

 

NumberCompanyStatusDate
1XXXGD29/09/2014 15:58:27
1XXXUC29/09/2014 12:43:39
2YYYGD30/09/2014 15:58:27
2YYYUD30/09/2014 12:43:39
3ZZZGD27/09/2014 15:58:27
3ZZZUC27/09/2014 12:43:39

 

Need to create table or matrix to show the below output. So need help in achiving the below output in Power BI

 

NumberCompanyStatus Hours Difference Between
  GDUC 
1XXX29/09/2014 15:58:2729/09/2014 12:43:393:15
2YYY30/09/2014 15:58:2730/09/2014 12:43:393:15
3ZZZ27/09/2014 15:58:2727/09/2014 12:43:393:15

 

Any help in achiving this Hours Difference Between calculation in Power or SQL.

 

I tried in SQL and got the below output

 

NumberCompanyGD DateUC DateHours Difference Between
1XXX29/09/2014 15:58:27NULL 
1XXXNULL29/09/2014 12:43:39 
2YYY30/09/2014 15:58:27NULL 
2YYYNULL30/09/2014 12:43:39 
3ZZZ27/09/2014 15:58:27NULL 
3ZZZNULL27/09/2014 12:43:39 

 

Thanks,

Maya

2 ACCEPTED SOLUTIONS
wini_R
Solution Supplier
Solution Supplier

Hi @Maya2988,

 

One way to achieve this is to create a new table based on the original one to get the expected structure and also set the right format for duration column:

wini_R_1-1715092539182.png

 

 

View solution in original post

Hey @Maya2988,

 

Just include that column in SUMMARIZE function:

table1 = 
ADDCOLUMNS(
    SUMMARIZE(
        tabA,
        tabA[Company],
        tabA[Number]
    )
    , "GD time", CALCULATE(SELECTEDVALUE(tabA[Date]), tabA[Status] = "GD")
    , "UC time", CALCULATE(SELECTEDVALUE(tabA[Date]), tabA[Status] = "UC")
    , "duration", CALCULATE(SELECTEDVALUE(tabA[Date]), tabA[Status] = "GD") - CALCULATE(SELECTEDVALUE(tabA[Date]), tabA[Status] = "UC")
)

View solution in original post

5 REPLIES 5
Maya2988
Helper I
Helper I

Hi @wini_R 

 

Thanks for the help. This helps me a lot and learnt a lot.Please tell me how to add Number also to this new table dax query (As i am new to power bi dont know how to do this)

Hey @Maya2988,

 

Just include that column in SUMMARIZE function:

table1 = 
ADDCOLUMNS(
    SUMMARIZE(
        tabA,
        tabA[Company],
        tabA[Number]
    )
    , "GD time", CALCULATE(SELECTEDVALUE(tabA[Date]), tabA[Status] = "GD")
    , "UC time", CALCULATE(SELECTEDVALUE(tabA[Date]), tabA[Status] = "UC")
    , "duration", CALCULATE(SELECTEDVALUE(tabA[Date]), tabA[Status] = "GD") - CALCULATE(SELECTEDVALUE(tabA[Date]), tabA[Status] = "UC")
)

Thanks @wini_R . It works perfectly. Last question regarding performance. Creating new table using DAX in power bi will create any performace issue in future. 

Yes, that might impact the performance depending on how big the original table is. It is always recommended (whenever possible) to do any tranformations in source system or as close to the source as possible (i.e. in SQL db).

wini_R
Solution Supplier
Solution Supplier

Hi @Maya2988,

 

One way to achieve this is to create a new table based on the original one to get the expected structure and also set the right format for duration column:

wini_R_1-1715092539182.png

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.