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
LadaA
Frequent Visitor

Help Making a Calculated Table using DAX (Examples and Data provided)

Hi everyone,

 

I'm new to Power BI and I'm trying to create a new table for this project within BI using DAX functions, any help would be greatly appreciated. I've had some success with using crossjoin to create the table template but I'm now stuck with the final calculation. 

 

All the excel tables have been pasted below if you'd like to take a look at it.

 

The TLDR is that there are farms that are running from "Start Date" to "End Date", each farm produces a fixed yearly yield of a specific product: Fruit, Vegies, Grain, Meat (Measured in Annual LB Produced). Each farm is individually instructed what % of their yearly LB produced is to be sent to any given state. How can I write a DAX function that will make a table that accumulates all of the produce sent to each state for any given year? Examples and a more in-depth breakdown is provided below.

 

Thank you all for your time, if you have any questions please leave a comment and I'll answer it asap.

=====================================================================

 

The premise of this project is that there is a large grocery store company that owns multiple farming plants that each produce a fix yearly yield of a specific product, measured in LB of Produce. The company has a goal to supply x states with y LB of products by year 2030.

 

Example Inputs

Main Parameters:

Grocery Store Company

 

 

Start Year

2019

End Year

2030

 

Total Produce Needed by State:

State

LB of Produce Needed

AR

167,755.15

CA

623,050.39

MI

312,832.94

NH

44,286.41

OH

672,908.93

TX

656,893.41

VA

422,508.56

 

The company notates how much of the plants yearly produces goes to a given state by assigning the states column the %. Meaning that if they would like Plant 1 to send 20% of its 47563 Annual LB Produced to California they'd mark CA with 0.20. 

Which would mean that in the year 2019 CA receives 9251.98 Annual LB of Fruit since the plant starts on the 11th of January but in the following years until the End Date year CA would be receiving 9512 Annual LB of Fruit from Plant 1.

 

Farming Projects:

PlantPlant NameProduct TypeStart DateEnd DateAnnual LB ProducedALAKAZARCACOCTDEFLGAHIIDILINIAKSKYLAMEMDMAMIMNMSMOMTNENVNHNJNMNYNCNDOHOKORPARISCSDTNTXUTVTVAWAWVWIWY
1AFruit1/11/2019  11/1/2036   4756300000.20000000000000000000000000000000.10000000.70000000
2BMeat1/1/20196/1/2023 2212800000000000000000000000000000000000000000000010000
3CFruit11/1/202311/1/2035 9786000010000000000000000000000000000000000000000000000
4DVegies1/1/202512/1/2034 2465000000000001000000000000000000000000000000000000000
5EGrain4/1/20241/1/2037 27280400000000000000000000000000001000000000000000000000
6FMeat11/1/20226/1/2023 365420000.10000000.3000000000000000000.20000000.10000000.2000.1000

0

 

Example of Final Table needed for 2022:

*The Final Table should go from Start Year to End Year listed in the Main Parameters

*I'll try to provide a table for 2019-2022 in the comments as I've hit my character limit

*Other category = LB of Produce Needed - (Fruit + Vegies + Grain + Meat)

YearStateTypeLB of Produce
2022ARFruit0.00
2022ARVegies0.00
2022ARGrain0.00
2022ARMeat610.70
2022AROther167144.45
2022CAFruit9512.60
2022CAVegies0.00
2022CAGrain0.00
2022CAMeat0.00
2022CAOther613537.79
2022MIFruit0.00
2022MIVegies1826.10
2022MIGrain0.00
2022MIMeat0.00
2022MIOther311006.84
2022NHFruit0.00
2022NHVegies0.00
2022NHGrain0.00
2022NHMeat1221.40
2022NHOther43065.01
2022OHFruit4756.30
2022OHVegies0.00
2022OHGrain0.00
2022OHMeat610.70
2022OHOther667541.93
2022TXFruit33294.10
2022TXVegies0.00
2022TXGrain0.00
2022TXMeat1221.40
2022TXOther622377.91
2022VAFruit0.00
2022VAVegies0.00
2022VAGrain0.00
2022VAMeat22738.70
2022VAOther399769.86
1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @LadaA,

Here's the file - https://www.dropbox.com/s/5ds3lq8u8m1qfcy/community-grocery.pbix?dl=0

I am not sure the calculations are 100% correct - up to you to check and validate.

Others calculated via your formula turn negative in 2023+ for some of the states, but that's correct in terms of figures.

Unfortunately, my solution requires a couple of permanent temporary tables. Hope that won't be a problem for you.

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

View solution in original post

2 REPLIES 2
barritown
Super User
Super User

Hi @LadaA,

Here's the file - https://www.dropbox.com/s/5ds3lq8u8m1qfcy/community-grocery.pbix?dl=0

I am not sure the calculations are 100% correct - up to you to check and validate.

Others calculated via your formula turn negative in 2023+ for some of the states, but that's correct in terms of figures.

Unfortunately, my solution requires a couple of permanent temporary tables. Hope that won't be a problem for you.

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

devanshi
Helper V
Helper V

TotalProduceSent = CALCULATE( SUM(Farms[Annual LB Produced]),
                                     FILTER( Farms, Farms[Year] = EARLIER(CombinationTable[Year]) &&
                                                   Farms[Product] = EARLIER(CombinationTable[Product]) &&
                                                    RELATED(States[State]) = EARLIER(CombinationTable[State])
                                              )
)

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.