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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Need help

Requirement

-- Add the parameters for the stored procedure here

--@endofquarter user will select from slicer date picker
    @endofquarter datetime

 

   --@yearstart will get from @endofquarter
    declare @yearstart datetime
    SET        @yearstart = DATEADD(yy, DATEDIFF(yy, 0, @endofquarter), 0)    

 

-- This SQL query i need to implememt in power bi 


    Select    SUM(CASE    
            WHEN full_date >= @yearstart THEN total_paid
            ELSE 0
            END) as YTD_Paid
    from    fact.fact_table
    where    Full_Date>=@endofquarter

-----------------------------------------------------------------------------

I tried the below DAX query in Power Bi, but it did not work. Please assist me.

 

Ytd_PD =
Var endofquarter=MAX('Date'[Date]) //created date table for the date picker (@endofquarter)
var  yearstart= DATE(YEAR(Max('Date'[Date])),1,1)
//Var SumofTd_Pd=SUM(fact_table[total_paid])
Var Result=
            CALCULATE(SUM(fact_table[total_paid]),
            FILTER( facttable,
            IF(
               MAX(fact_table[Full_date])>=yearstart,fact_table[total_paid],0
                ) &&
                fact_table[Full_date] <=endofquarter   
            )
            

Return Result


1 REPLY 1
vanessafvg
Community Champion
Community Champion

not sure if i quite understand your requirement but i think if you move your if statement that willl help

 

Ytd_PD =
VAR endofquarter =
MAX ( 'Date'[Date] )
VAR yearstart =
DATE ( YEAR ( MAX ( 'Date'[Date] ) ), 1, 1 )
VAR SumofTd_Pd =
SUM ( fact_table[total_paid] )
VAR Result =
CALCULATE (
SUM ( fact_table[total_paid] ),
FILTER (
fact_table,
fact_table[Full_date] >= yearstart
&& fact_table[Full_date] <= endofquarter
)
)
RETURN
IF ( ISBLANK ( Result ), 0, Result )





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.