Vishal modi
Vishal modi

Reputation: 1720

How to display Subtraction of two fields and display as a column in PowerBI?

I am using SQL server data base. I need to display total no of nights based on checkindate and checkout date. i am new in Power BI.

I tried by quick measure but it is not working.

Upvotes: 0

Views: 115

Answers (1)

Andrey Nikolov
Andrey Nikolov

Reputation: 13460

You can do this in different ways - calculate the duration in the database, add custom column in M or column in DAX.

In SQL Server use select query like this:

select checkindate, checkoutdate, datediff(day, checkindate, checkoutdate) as duration from table

In M (Power Query) - click Edit queries to open Power Query editor and then Add Column -> Custom column:

enter image description here

Duration.Days(Duration.From([checkoutdate]-[checkindate]))

enter image description here

In DAX - right click your table and select New column:

enter image description here

Duration_DAX = DATEDIFF('Table'[checkoutdate]; 'Table'[checkindate]; DAY)

enter image description here

Note, that depending on your settings, you may have to use comma (,) instead of semicolon (;) in the DAX expression above.

Upvotes: 1

Related Questions