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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mydatastories
New Member

How To calculate Frequency of continuous dates based on ID in Power BI

Hi everyone,

I was just wondering if anyone can advise the best/efficient way to calculate frequency based on continuous dates and record id.

Scenario

  • I want to be able to calculate these customers that are Frequent and Non-Frequent (status)based on the time their stay at the hotel and this must be only on the weekday (Monday -Friday)
  • I have [CheckinDate] and [CheckOutDate] which give days (but this is required to calculate only Monday to Friday Stays, so we’re excluding weekend )
  • [Customer type] is the status when a customer has meet which we’re trying to calculate and this will be our alias column
  • I have [Customer ID] which is the same every time when a customer stays in a hotel, so one [Customer ID] can have many stays but I am interested in these based on below business logic.

Business Logic

  1. 10 days (Monday -Friday) or a 4 period/frequency of staying in a hotel in 6-months period based on check-in date
  2. 20 days (Monday – Friday) or a 7 period/frequency of staying in a hotel in a 12-month period based on check-in date
SELECT  [Customer ID]
      ,[CheckinDate]
      ,[CheckOutDate]
      ,[TotalDaysInHotel]
      ,[Customer type ]---This is alias table and is what we're trying to calculate(Frequency)
  FROM [Dev].[dbo].[Customer]
  WHERE [Customer ID] = '1'

 

Anything else with earlier, [CheckOutDate] than, [CheckinDate] is Data Quality issue as is not logically possible

I have attached the final results with Alias column [Customer type ] which is a result of above business logic

 

Many thanks for your help in advance.

 

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @mydatastories,

 

If you can please share some sample data/pbix file (it should has same structure as original file) and expected result to help us clarify your requirement and test to coding formula.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
mydatastories
New Member

Hi everyone,

I was just wondering if anyone can advise the best/efficient way to calculate frequency based on continuous dates and record id.

Scenario

  • I want to be able to calculate these customers that are Frequent and Non-Frequent (status)based on the time their stay at the hotel and this must be only on a weekday (Monday -Friday)
  • I have [CheckinDate] and [CheckOutDate] which give days (but this is required to calculate only Monday to Friday Stays, so we’re excluding weekend )
  • [Customer type] is the status when a customer has meet which we’re trying to calculate and this will be our alias column
  • I have [Customer ID] which is the same every time when a customer stays in a hotel, so one [Customer ID] can have many stays but I am interested in these based on below business logic.

Business Logic

  1. 10 days (Monday -Friday) or a 4 period/frequency of staying in a hotel in 6-months period based on check in date
  2. 20 days (Monday – Friday) or a 7 period/frequency of staying in a hotel in 12-months period based on check in date

SELECT  [Customer ID]

      ,[CheckinDate]

      ,[CheckOutDate]

      ,[TotalDaysInHotel]

  FROM [Dev].[dbo].[Customer]

 

Anything else with earlier ,[CheckOutDate]than ,[CheckinDate] is Data Quality issue as is not logically possible

I have attached the final results with Alias column [Customer type ] which is a result of above business logic

 

Many thanks for your help in advance.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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