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
KristyP
Helper I
Helper I

DAX Calucation

Hi,

 

I have two related tables. I am trying to find a value in one table based on a range ( min & max) and a category from the first table. The value I require is in the second table, seperate column for the category and the min & max, the value I require is in a seperate column again.

 

i.e

I have a series of categories, with products that fit into the different categories. Each product has a different (and known) amount of usage. The related table contains a list of products and value based on usage (the value is based on a range e.g 2400 - 7200, there are several different ranges depending on category and usage).

1 ACCEPTED SOLUTION

Sure, I can do this tomorrow.

View solution in original post

18 REPLIES 18
devanshi
Helper V
Helper V

first make the measure of total sales.
then create one table which include all ranges according to your range you want.

then use this measure:

rangevalues = Calculate([totalsale measure name],
VAR currentrange=

FILTER(

table1,table2,

AND(tablename[value]<=range tablename,

          tablename[value]>=range tablename))

RETURN

  rangevalue

With reference to the total sales measure, which column from which table are you referring to?

KristyP
Helper I
Helper I

Thank you,

 

I have tried your solution, but am getting the followinf error:

A single value for column 'Product Group' in table 1 cannot be determined. This can happen when a measure refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

@KristyP 
This is supposed to be a calculated column in Table1 not a measure.

I haved used this calculation. But there are some issues with it not always picking up the correct value. This issue does not seem relate to any one particular Product Goup or band. Any ideas what could be casuing this issue?

@KristyP 
Can you provide a sample file that clarifies these inconsistencies?

 

I need to protect the information for work purposes. But I will complete a sample file tomorrow and send it through.

I have done this very quickly, please see below

KristyP_0-1686631174745.png

I made sure there was a relationship between the two tables

KristyP_1-1686631190581.png

 

Hi @KristyP 
Would you please share a download link of this sample file?

@KristyP 
The reason you're getting blanks is that the Names of the groups in the two tables do not match: One table says "Product A" and the other says "Product Group A" and so on. I created a new group column just to get itt work.

1.png2.png

Sorry, this is something I double checked in the actual one. The names are all correct. I can not find any consistency with the error. I will have 20 for one product gorup, 15 will read correct 1 will be blank and the rest reading incorrectly.

@KristyP 
Let's connect via teams or zoom if possible.

Sure, I can do this tomorrow.

KristyP
Helper I
Helper I

I have provided very basic form of the data I have to work with.

 

KristyP_0-1685405613403.png

KristyP_1-1685405882034.png

 

 

@KristyP 
Please try

Value =
MAXX (
    FILTER (
        Table2,
        Table2[Product Group] = Table1[Product Group]
            && Table2[Min Usage Range] <= Table1[Usage]
            && Table2[Max Usage Range] >= Table1[Usage]
    ),
    Table2[Value]
)

My apologies, I misunderstood.

 

I have tried this, but getting this error:

DAX expression operations do not support comparing values of type text with values of type integer. Consider the VALUE or FORMAT function to convert one of the values.

 

I have changed the Usage and value to text for the moment, which worked. Just concerned how this affect other calculation moving forward. Is there a better way to do this?

tamerj1
Super User
Super User

Hi @KristyP 
I might be better if you start with a sample data of both tables, indication the relationship if (exist) along with the expected result.

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.

Top Solution Authors