简体   繁体   中英

Create DAX to count number of occupied rooms per calendar month date in Power BI

I am new to power BI and dax, and have a question regarding calculating values by month. I am really using an excel formula and I am trying to use the wonders of power BI to help me filter this by month. I am calculating the number of days that customers stay: there is acolumn that calculates Lenght of stay - LOS is: [Check Out]-[Check In] but when it falls in 2 different months I would like to filter it by each month, how can I add this on the formula? I did look at this post ( Create DAX to count number of occupied rooms per calendar date in Power BI ) but it seems that my formula is much simpler and I tried to adapt using that information but still to complicated. Anyone can help me?

enter image description here

在此处输入图片说明

LOS4

LOS5

Can you try this formula (as a calculated column):

LOS = DATEDIFF('Date'[CheckIn];'Date'[CheckOut];DAY) 

在此处输入图片说明

Now I add 2 Columns First with the nights of First Month CheckIn and Other With the Nights of second Month of CheckOut:

LOS(MonthOfCheckIn) = IF(MONTH('Date'[Check In])>=MONTH('Date'[Check Out]);DATEDIFF('Date'[Check In];'Date'[Check Out];DAY);DATEDIFF('Date'[Check In];ENDOFMONTH('Date'[Check In]);DAY)+1)

LOS(MonthOfCheckOut) = IF(MONTH('Date'[Check In])<MONTH('Date'[Check Out]);DATEDIFF(STARTOFMONTH('Date'[Check Out]);'Date'[Check Out];DAY);0)

it works for me (as in the above image). Tell me please if this resolve your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM