Forum Discussion
Build a dynamic calculated comlumn
I want to build a dynamic calculated column [TotalWagePerDay] like below using DAX:
- If [DayType] is "Holiday" then [TotalWagePerDay]=[HourlyWage] * [Hours] * 2
- If [DayType] is "Weekday" then [TotalWagePerDay]=([HourlyWage] * [Hours] ) + 1.5 * ([Hours]-8)
This is my model :
- Table [Time] contains [Date] and [Hours] columns
- Table [Dates] contains [DayType]
- Table [Employees] contains [Employee] and [Hourly Wage]
I created a calculated column to get the [DayType],
DayType = RELATED(Dates[Day Type])then created the [TotalWagePerDay] like below :
TotalWagePerDay =IF ('Time'[DayType]= "Holiday", RELATED(Employees[Hourly Wage]) * [Hours] * 2,(RELATED(Employees[Hourly Wage]) * [Hours] ) + 1.5 * ([Hours]-8))
2 Replies
- parry2kSuper User
amirabedhiafi here it is:
TotalWagePerDay = IF (RELATED ( DatesTable[DayType] ) = "Holiday" then [HourlyWage] * [Hours] * 2, [TotalWagePerDay]=([HourlyWage] * [Hours] ) + 1.5 * ([Hours]-8) )Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
- amirabedhiafiImpactful Individual
I created a calculated column to get the [DayType],
DayType = RELATED(Dates[Day Type])then created the [TotalWagePerDay] like below :
TotalWagePerDay =IF ('Time'[DayType]= "Holiday", RELATED(Employees[Hourly Wage]) * [Hours] * 2,(RELATED(Employees[Hourly Wage]) * [Hours] ) + 1.5 * ([Hours]-8))