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! Request 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.
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 |
|---|---|
| 8 | |
| 6 | |
| 4 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 25 | |
| 17 | |
| 8 | |
| 8 | |
| 7 |