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
bvilten
Helper III
Helper III

ARGHH A.K.A. DAX, need help creating DAX from pseudo code

Hello All,

 

I have reached the end of my capabilities it seems. I have an urgent request for help in creating DAX. In essance the user specifies a date range and if the contract is in that date range add that contract to the display and show Contract Name, Total Price, Annual Cost. I have thought about making a list of months/years betwen FromDate and ToDate and another list of months/years between RequestedStartDate (RSD) and RequestedEndDate(RED) and using some sort of IF is in function, but haven't gotten very far down that road yet.

 

The logic I am trying to create in DAX is as follows:

 

Variables input by user

(not really sure how to capture this either, I have tried using the Date Range slicer based on a date table not connected to anyother table but SELECTED or SELECTEDVALUE [Start] and [End] doesn't seem to work)


Requested Start Date (RSD)
Requested End Date (RED)

// eliminate any contracts which start after the contract period requested
If the RSD is > To Date, skip record
// eliminate any contracts which end prior to the contract period requested
If the RED is < From Date, skip record

    If Full Contract
        If From Date (Year) = RSD (Year) and To Date (Year) >= RED
            AnnualCost = Total Price
        Else
            AnnualCost = $0

    If Annual or Annual Variable Payment
         //Calculated Contract Years (CCY)
        If FromDate.year = ToDate.year
            CCY = 1
        Else
           CCY = ToDate.year - FromDate.year (int)

    If CCY = 1
         AnnualCost = TotalPrice (Float)
    Else
         AnnualCost = TotalPrice/CCY (Float)

 

Contract NamePayment ScheduleTotal PriceAnnual CostFrom DateTo Date
WidgetsAnnual60,000.0060,000.007/15/20197/15/2020
GizmosAnnual80,000.0020,000.006/01/20186/01/2021
Do-DadsFull Payment200,000.000* 01/01/201601/01/2021

 

*0 will show if RSD.year is after FromDate.year else Total Price will be shown 

1 REPLY 1
Anonymous
Not applicable

The description of the calculation is ambiguous because of the very last line of your post.

Please state the algorithm unambiguously.

Best
D

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.