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

Is it possible to solve this problem with DAX?

Morning All!

I was wondering if it would be possible to solve with Dax a problem like this:

 

  • I have a table of stores and their limits.
  • I have a table of boxes to be assigned to the stores

Any ideas to define a column "GiveTo" that assigns boxes to stores? 

IDLimit  IdUnitsGiveTo
Store 1500  Box 1100Store 1
Store 2400  Box 2300Store 1
Store 3 300  Box 3200Store2
    Box 4200Store2
    Box 5100Store 3

 

It would be easy to solve this  in Java/C...... ( While assigned<limit do sth...), but what about DAX?

Thanks in advance!

4 REPLIES 4
Anonymous
Not applicable

Hi @sashaxiv , 

 

I think your calculate logic contains looping. As far as I know, dax doesn't support looping currently.  Here I suggest to try to Power Query.

Here I suggest you to try List.Generate function.

For reference: List.Generate in Power Query: Tutorial with Easy Examples

Accumulative, conditional accumulative in Power Query

 

Best Regards,
Rico Zhou

 

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

johnt75
Super User
Super User

You'd need an index column or similar on both tables, to define the precedence of the stores and the order in which the boxes should be given out.

Then you could create a helper table like

Store limits = ADDCOLUMNS( SUMMARIZE( 'Table1', 'Table1'[Index], 'Table1'[Store]), "Upper bound",
var currentIndex = SELECTEDVALUE( 'Table1'[Index])
return CALCULATE( SUM('Table1'[Limit]), 'Table1'[Index] <= currentIndex)
)

and you could add a new column to the other table like

Give to store =
var currentIndex = 'Table2'[Index]
var totalUnits = CALCULATE( SUM('Table2'[Units]), 'Table2'[Index] <= currentIndex)
var summaryTable = TOPN(1, FILTER('Store limits', 'Store limits[Upper bound] >= totalUnits), 'Store limits'[Index], ASC)
return SELECTCOLUMNS( summaryTable, "@val", [Store])
sashaxiv
Frequent Visitor

On the limit. For example, store 1 has a limit of 500. Boxes can be assigned to store1 if the sum of units of all assigned boxes is less than 500.

Arul
Super User
Super User

@sashaxiv ,

It is possible, based on what condition do you need to define the column?

 

Thanks,

Arul





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


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.