Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
In above pic , there is some logic, But I unable to write proper DAX add column logic.
I want to add the column"No of Nights ", that takes the reference of Tour ref no, supp type and booking date. If tour ref has >=2 of count of supp type HTL, It takes dist.count of booking dates and indicates that number to all the supp type for Perticular Tour ref no.
How can I do it...Please help
Solved! Go to Solution.
To create the "No of Nights" column based on your described logic in Power BI using DAX:
The "No of Nights" value should then apply to all rows within the same TourRefNo.
Step 1: Create a calculated column for counting distinct booking dates of "HTL":
Step 2: Create the "No of Nights" column based on the count of HTL booking dates:
Let me know if you'd like additional help!
 
					
				
		
Thanks for the reply from 123abc , please allow me to add some more information:
Hi  @DanduMani104 ,
You can use the var() function to store the result of an expression as a named variable, which can then be passed as a parameter to other metric expressions, saving code length and memory consumption.
VAR keyword (DAX) - DAX | Microsoft Learn
1. Create calculated column.
Number of Nights =
var _count=
CALCULATE(
    DISTINCTCOUNT('Table'[BookingDate]),
    FILTER('Table',
    [TourRefNo]=EARLIER('Table'[TourRefNo])&&[SuppType]="HTL"))
return
IF(
    _count=BLANK(),0,_count)Min 2 night =
 IF(
    [Number of Nights]>=2,"y","n")2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
 
					
				
		
Thanks for the reply from 123abc , please allow me to add some more information:
Hi  @DanduMani104 ,
You can use the var() function to store the result of an expression as a named variable, which can then be passed as a parameter to other metric expressions, saving code length and memory consumption.
VAR keyword (DAX) - DAX | Microsoft Learn
1. Create calculated column.
Number of Nights =
var _count=
CALCULATE(
    DISTINCTCOUNT('Table'[BookingDate]),
    FILTER('Table',
    [TourRefNo]=EARLIER('Table'[TourRefNo])&&[SuppType]="HTL"))
return
IF(
    _count=BLANK(),0,_count)Min 2 night =
 IF(
    [Number of Nights]>=2,"y","n")2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
To create the "No of Nights" column based on your described logic in Power BI using DAX:
The "No of Nights" value should then apply to all rows within the same TourRefNo.
Step 1: Create a calculated column for counting distinct booking dates of "HTL":
Step 2: Create the "No of Nights" column based on the count of HTL booking dates:
Let me know if you'd like additional help!
 
					
				
				
			
		
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
 
            | User | Count | 
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | 
| User | Count | 
|---|---|
| 23 | |
| 14 | |
| 11 | |
| 10 | |
| 9 |