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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
TL_LCH
Frequent Visitor

Help creating dynamic trend line.

I am relatively new to PowerBI and was struggling to find an answer. I am trying to find a way to create a line graph with YTD data being used for the first part and calculated data for today to EOY. e.g:

month123456789101112
data51016232832354045505560

In blue is data I can get and in red is data I have to forecast based on YTD trend. 

I have tried creating a for loop:

Trend_forloop =
// Provide some starting values
VAR __sum = [raw data]
VAR __loopTable = GENERATESERIES(1,12)
VAR __loopTable1 = ADDCOLUMNS(__loopTable,"__sum",__sum + SUMX(FILTER(__loopTable,[Value]<=EARLIER([Value])),[Value]))
VAR __max = 12
RETURN

//here is where the issue arises
CALCULATE(VALUES(__loopTable1[__sum]),
FILTER(ALL(__looptable1[Value], __looptable1[Value] = max (__loopTable1[Value]))))​

 

 


As you can see above I am unsure how to do the final step here. Any insights would be appreciated. 

I am also open to any alternative ways of doing this (not a for loop).

 

Thanks

1 REPLY 1
amitchandak
Super User
Super User

@TL_LCH , Can you share raw data.

You need like

YTD = CALCULATE(if(Max(Date[Date]) <= eomonth(Today(),-1),  SUM(Actual[Actual]) ,  SUM(Forecast[Forecast]) ) ,DATESYTD('Date'[Date],"12/31"))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors