Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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!
User | Count |
---|---|
25 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
27 | |
13 | |
11 | |
9 | |
6 |