Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Gopal_PV
Helper III
Helper III

How to use IF and Datediff in a measure

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.

1 ACCEPTED SOLUTION
_elbpower
Resolver III
Resolver III

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.

View solution in original post

1 REPLY 1
_elbpower
Resolver III
Resolver III

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.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.