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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

How to convert the case statement from cognos to power bi ?

Hello All,

 

Can anyone please help me in converting /rewriting the below cognos case statement in to power bi . 

 

Sum(Sales)   *
case
when [Accounting Date] < [FROM_DATE]
and [Transaction Effective Date] <= [TO_DATE]
and [Expiration Date] >= [FROM_DATE]
then _days_between(least([TO_DATE]+1, _add_days([Expiration Date],1)), greatest([FROM_DATE], _add_days([Transaction Effective Date],1)))
/ _days_between(_add_days([Expiration Date],1),_add_days([Transaction Effective Date],1))

 

Below is the expression i tried 

 

DateDiffEX = (DATEDIFF( MIN(Max(FACT_TRANSACTION[Loss Date]),DATEADD(DIM_TRANSACTION[Policy Expiration Date],1,DAY)), MAX(MIN(FACT_TRANSACTION[Loss Date]),DATEADD(DIM_TRANSACTION[Transaction Effective Date],1,DAY)),day))

 

Please help .

3 REPLIES 3
Anonymous
Not applicable

Hi  @Anonymous ,

 

Can you show the expected results in the form of pictures or text? We can better help you solve the problem.

 

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.

lbendlin
Super User
Super User

You use a case statement for a single comparison - could have used an if statement instead.  You use a [Loss Date] column in the DAX example - where is that coming from?

 

Usually you want to formulate the business need in plain text, and then translate it into code.

Anonymous
Not applicable

HI @lbendlin 

Below is the sample data of the policy table and we have seperate calendar table which is used as a date dimension.

 

Policy NoPolicy Start Date

Policy Accounting Date

Policy End DatePremium Amount
abc12301-01-201801-02-201801-01-20191000
abc12301-01-201901-02-201901-01-2020900
abc12301-01-202001-02-202002-01-2021750
abc12403-02-202003-03-202003-02-20211500
abc12509-06-202109-07-202109-06-20221500

 

We are trying to calculate Earned Premium based on date filter and we are trying to convert the following expression . 

Sum(Written Premium)   *
case
when [Accounting Date] < [FROM_DATE]
and [Policy Start Date] <= [TO_DATE]
and [End Date] >= [FROM_DATE]
then _days_between(least([TO_DATE]+1, _add_days([End Date],1)), greatest([FROM_DATE], _add_days([Start Date],1)))
/ _days_between(_add_days([End Date],1),_add_days([Start Date],1))

 

Note : Policy Number is not unique 

 

[FROM_DATE] and [TO_DATE] will be coming from the user selection on date slicer . 

 

Thanks in advance .

 

Regards ,

Sandeep 

 

 

 

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors