Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi Friends,
I got a requirement to create measure for to get number Days of using IF Condition.
EX:
IF(Product Category="Cycle",
(DATEDIFF(Product Category[First_date],Product Category[Last_date],DAY)))
Source: SSAS Anlaysis services Model
Due to Model complexity my client is telling me to create Measure instead of CalculateColumn.
How to do this.
Can you please help me in this.
Solved! Go to Solution.
To create a measure in a SSAS Analysis Services model that calculates the number of days using an IF condition based on the "Product Category," you can follow these steps:
1. Launch SQL Server Data Tools (SSDT) or SQL Server Management Studio (SSMS), depending on your preferred tool for working with SSAS.
2. Open your SSAS project and navigate to the appropriate cube or tabular model where you want to create the measure.
3. In the Measures section of your cube or tabular model, right-click and choose "New Measure."
4. Provide a name for your measure, for example, "Days in Cycle."
5. In the Expression box, you can use the following DAX formula:
Days in Cycle =
IF(
'Product Category'[Product Category] = "Cycle",
DATEDIFF(
'Product Category'[First_date],
'Product Category'[Last_date],
DAY
)
)
This DAX measure calculates the number of days between "First_date" and "Last_date" only if the "Product Category" is "Cycle." If it's not "Cycle," the measure returns blank.
6. Save your changes in your SSAS project.
7. Deploy and process your SSAS project to make the measure available in your SSAS database.
Now, you can use the "Days in Cycle" measure in your client tools, such as Excel or Power BI, to get the number of days based on the "Product Category." When you filter or aggregate your data by "Product Category," the measure will dynamically calculate the number of days for "Cycle" products.
To create a measure in a SSAS Analysis Services model that calculates the number of days using an IF condition based on the "Product Category," you can follow these steps:
1. Launch SQL Server Data Tools (SSDT) or SQL Server Management Studio (SSMS), depending on your preferred tool for working with SSAS.
2. Open your SSAS project and navigate to the appropriate cube or tabular model where you want to create the measure.
3. In the Measures section of your cube or tabular model, right-click and choose "New Measure."
4. Provide a name for your measure, for example, "Days in Cycle."
5. In the Expression box, you can use the following DAX formula:
Days in Cycle =
IF(
'Product Category'[Product Category] = "Cycle",
DATEDIFF(
'Product Category'[First_date],
'Product Category'[Last_date],
DAY
)
)
This DAX measure calculates the number of days between "First_date" and "Last_date" only if the "Product Category" is "Cycle." If it's not "Cycle," the measure returns blank.
6. Save your changes in your SSAS project.
7. Deploy and process your SSAS project to make the measure available in your SSAS database.
Now, you can use the "Days in Cycle" measure in your client tools, such as Excel or Power BI, to get the number of days based on the "Product Category." When you filter or aggregate your data by "Product Category," the measure will dynamically calculate the number of days for "Cycle" products.