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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Ale
Resolver II
Resolver II

YTD value as Calculated Column (not measure) in Data View

I'm trying to create 2 columns with the Year to Date values for each record in my table, but keeping all other descriptive data (Category, Product, etc) into account.

 

I attached a table with the example below. I have a data with 4 columns (Date, Category, Product, Value). So, for each Category and Product, I want to calculate the YTD for each of the rows of the table. The same logic will be then applied to a second column, but taking previous month YTD instead of current month.

 

Ale_3-1659014755883.png

 

Any help on that?

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Ale ;

Try to create a column by dax.

YTD = 
 CALCULATE(SUM('Table'[Value]),FILTER('Table',[Category]=EARLIER('Table'[Category])&&[Product]=EARLIER('Table'[Product])), DATESYTD('Table'[Date]))
YTD-M1 = 
CALCULATE(MAX('Table'[YTD]),FILTER('Table',[Category]=EARLIER('Table'[Category])&&[Product]=EARLIER('Table'[Product])&&EOMONTH([Date],0)=EOMONTH(EARLIER('Table'[Date]),-1)))+0

The final show;

vyalanwumsft_0-1659508390904.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yalanwu-msft
Community Support
Community Support

Hi, @Ale ;

Try it.

YTD-M1 =
CALCULATE (
    MAX ( 'Table'[YTD] ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[Category], 'Table'[Product] ),
        EOMONTH ( [Date], 0 ) = EOMONTH ( EARLIER ( 'Table'[Date] ), -1 )
    )
) + 0

The 30 descriptive Data (not only Category and Product) you said need to be input one by one. The descriptive data (descriptive data) can not be supported by all the columns at once.


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-yalanwu-msft
Community Support
Community Support

Hi, @Ale ;

Try to create a column by dax.

YTD = 
 CALCULATE(SUM('Table'[Value]),FILTER('Table',[Category]=EARLIER('Table'[Category])&&[Product]=EARLIER('Table'[Product])), DATESYTD('Table'[Date]))
YTD-M1 = 
CALCULATE(MAX('Table'[YTD]),FILTER('Table',[Category]=EARLIER('Table'[Category])&&[Product]=EARLIER('Table'[Product])&&EOMONTH([Date],0)=EOMONTH(EARLIER('Table'[Date]),-1)))+0

The final show;

vyalanwumsft_0-1659508390904.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yalanwu-msft ,

 

your solution works fine for this dummy file. However, in my real world case, I have a table with more than 30 descriptive data (not only Category and Product). In that case, I presume I would have to write down all the columns of my table in the DAX.

 

Is there any way we could get this logic working for all columns without having to type them one by one?

amitchandak
Super User
Super User

@Ale , Try like

 

YTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

YTD +1 =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1*MONTH(_max))+2
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

ISFILTERED in a calculated column? I dont think so

@amitchandak ,this is returning the same values as in the column "Value", not summing the YTD.

 

Ale_0-1659015727305.png

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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