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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Eddyns
New Member

Calculate percentage with specific variables

Hello! 

 

Im trying to calculate percentage sold items of ingoing stock since last time we recived new goods. 

 

DepartmentSold itemsDateOutgoing days since new stockIngoing Stock
Sweden1021.05.20231100
Sweden1522.05.2023290
Sweden2023.05.2023375
Denmark1521.05.20231100
Denmark1022.05.2023285
Sweden524.05.2023195
Denmark1024.05.20231100
Denmark1525.05.2023290

 

Like the table shown, the data is something like that. 

So I would like to calculate the percentage from department Denmark when the date is closest to today, and the "Outgoing days since new stock" is 1. So for Denmark in this example, it would show "25.05.2023" and a percentage of 15%. 

 

Any ideas how to do this? 

2 REPLIES 2
Anonymous
Not applicable

Hi @Eddyns ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a calculated column.

 

closest to today = ABS(DATEDIFF('Table'[Date],TODAY(),DAY))

 

(3)We can create a measure. 

 

Measure = 
var _min=CALCULATE(MIN('Table'[closest to today]),FILTER(ALL('Table'),'Table'[Department]=MAX('Table'[Department])  && 'Table'[Outgoing days since new stock]=1))
var _date =CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Department]=MAX('Table'[Department]) && 'Table'[closest to today]=_min))
var _sold=CALCULATE(MAX('Table'[Sold items]),FILTER(ALL('Table'),'Table'[Department]=MAX('Table'[Department]) && 'Table'[Date]=_date))
var _stock=CALCULATE(MAX('Table'[Ingoing Stock]),FILTER(ALL('Table'),'Table'[Department]=MAX('Table'[Department]) && 'Table'[Date]=_date))
return DIVIDE(_sold,_stock,0)

 

(4) Then the result is as follows.

vtangjiemsft_0-1684895180192.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Eddyns
New Member

Dont know what happend to the table. 

But "Outgoing days since new stock" has these values: 

 

Outgoing days since new stock
1
2
3
1
2
1
1
2

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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