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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Paulyeo11
Impactful Individual
Impactful Individual

C1000 How to compute YTD for COGS ?

Hi All

I have below raw data , I like to compute YTD COGS amount.

My PBI File :-

https://www.dropbox.com/s/v578c2yp58eh70z/HOW%20TO%20COMPUTE%20REVENUE%20YTD%20V0002.pbix?dl=0

Paulyeo11_0-1602901139732.png

 

6 REPLIES 6
v-yangliu-msft
Community Support
Community Support

Hi  @Paulyeo11 ,

 

There are two ways to achieve:

1. Create a measure.

 

COGS_YTD_First =
CALCULATE (
    SUMX ( FILTER ( 'Table', 'Table'[PNL] = "COGS" ), 'Table'[AMOUNT] ),
    DATESYTD ( 'Date'[Date] ),
    'Table'[DATE]<=NOW(),
    'Table'[Year]=2020
)

 

2. Create two measure.

 

IF =
IF(MAX('Table (2)'[PNL])="COGS",
CALCULATE(SUM('Table (2)'[AMOUNT]),FILTER('Table (2)','Table (2)'[DATE]>=CALCULATE(MIN('Table (2)'[DATE]),ALL('Table (2)'[DATE])) && 'Table (2)'[DATE]<=NOW() && 'Table (2)'[Year]=2020 )),
BLANK()
)

 

 

COGS_YTD_Second =
var _new=SUMMARIZE('Table (2)','Table (2)'[DATE],"_value",[IF])
return IF(HASONEVALUE('Table (2)'[DATE]),[IF],SUMX(_new,[_value]))
)

 

3. Result.

v-yangliu-msft_0-1603187399847.jpeg

You can downloaded PBIX file from here.

 

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.

sktneer
Resolver I
Resolver I

Does this work for you?

COGS YTD =
CALCULATE (
    SUMX ( FILTER ( 'Table', 'Table'[PNL] = "COGS" ), 'Table'[AMOUNT] ),
    DATESYTD ( 'Date'[Date] )
)
Paulyeo11
Impactful Individual
Impactful Individual

Hi Sir

 

Thank you for your sharing. I have test your script , no error , but it include Nov 2020 year. since YTD is up to Oct only. 

 

My PBI file :-

https://www.dropbox.com/s/24fhwftffdluka9/HOW%20TO%20COMPUTE%20REVENUE%20YTD%20V0003.pbix?dl=0

 

Paulyeo11_0-1602912112212.png

 

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish

Thank you very much for your sharing.

your script pls helpp me exclude Dec 2019 amount.

Paulyeo11_0-1602913919216.png

 

You are welcome.  Filter it out (Filter pane)


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.