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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
vmsouza30
Helper I
Helper I

Calculation with the variables

In my table there is a grouping (Group  1,2,3) composed of several clients that are not repeated and the only field that is modified is the field "FACTOR".

 

Since my base client is client "E", and the value for the FACTOR field is not fixed, how to develop the DAX function using variables for the following case:

 

  • How to calculate how many customers within each group have a factor above customer "E"?
  • How do you calculate how many customers within each group have a factor below customer "E"?

Help me!!!

 

Table:

 tabela1.PNG

 

 

1 ACCEPTED SOLUTION
v-jiascu-msft
Microsoft Employee
Microsoft Employee

@vmsouza30

 

Hi,

 

Maybe you could try these formulas.

 

 

Above =
VAR E2014 =
    CALCULATE (
        MIN ( Table1[Factor2014] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
VAR E2015 =
    CALCULATE (
        MIN ( Table1[Factor2015] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
VAR E2016 =
    CALCULATE (
        MIN ( Table1[Factor2016] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
RETURN
    CALCULATE (
        COUNTROWS ( Table1 ),
        FILTER (
            Table1,
            'Table1'[Factor2014] > E2014
                || 'Table1'[Factor2015] > E2015
                || 'Table1'[Factor2016] > E2016
        )
    )
Below =
VAR E2014 =
    CALCULATE (
        MIN ( Table1[Factor2014] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
VAR E2015 =
    CALCULATE (
        MIN ( Table1[Factor2015] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
VAR E2016 =
    CALCULATE (
        MIN ( Table1[Factor2016] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
RETURN
    CALCULATE (
        COUNTROWS ( Table1 ),
        FILTER (
            Table1,
            'Table1'[Factor2014] < E2014
                || 'Table1'[Factor2015] < E2015
                || 'Table1'[Factor2016] < E2016
        )
)

 Calculation with the variables.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

 

 

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

View solution in original post

7 REPLIES 7
v-jiascu-msft
Microsoft Employee
Microsoft Employee

@vmsouza30

 

Hi,

 

Maybe you could try these formulas.

 

 

Above =
VAR E2014 =
    CALCULATE (
        MIN ( Table1[Factor2014] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
VAR E2015 =
    CALCULATE (
        MIN ( Table1[Factor2015] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
VAR E2016 =
    CALCULATE (
        MIN ( Table1[Factor2016] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
RETURN
    CALCULATE (
        COUNTROWS ( Table1 ),
        FILTER (
            Table1,
            'Table1'[Factor2014] > E2014
                || 'Table1'[Factor2015] > E2015
                || 'Table1'[Factor2016] > E2016
        )
    )
Below =
VAR E2014 =
    CALCULATE (
        MIN ( Table1[Factor2014] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
VAR E2015 =
    CALCULATE (
        MIN ( Table1[Factor2015] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
VAR E2016 =
    CALCULATE (
        MIN ( Table1[Factor2016] ),
        FILTER ( ALL ( Table1 ), 'Table1'[Clients] = "E" )
    )
RETURN
    CALCULATE (
        COUNTROWS ( Table1 ),
        FILTER (
            Table1,
            'Table1'[Factor2014] < E2014
                || 'Table1'[Factor2015] < E2015
                || 'Table1'[Factor2016] < E2016
        )
)

 Calculation with the variables.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

 

 

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

The solution it´s ok, great!!!!

LairdLight
Frequent Visitor

I agree with the other posts suggesting you reshape your data to have a single factor column and a year date dimension.

 

Having said that I think you're after something like this, I created a table like yours called Factor...

 

Then I created a new column called "Clientes Factor" which totals the three factor values for each client:

Clientes Factor = CALCULATE(SUMX(factor, factor[Factor 2014]+factor[factor 2015]+factor[factor 2016]))

 

Then I created a new measure called "Factor E Calc" which is Client Es factor total for comparison:

Factor E Calc= calculate(SUMX(factor, factor[Factor 2014]+factor[factor 2015]+factor[factor 2016]), Factor[clientes]="E")

 

Then to work around a circular dependency error I created a new measure called "Factor E" which is equal to the value I entered manually (copying the value calculated in "Factor E Calc):

Factor E = 6.1

 

Then I created a new column comparing "Clientes Factor" with "Factor E" I called it Factor Rating:

Factor Rating = if(Factor[Clientes Factor]<Factor[Factor E], "Less", (if(Factor[Clientes Factor]=Factor[Factor E], "Same", "Higher")))

 

Here's what the resulting table looks like:

groupclientesFactor 2014Factor 2015Factor 2016Clientes FactorFactor Rating
1A122.35.3Less
1B1.53.41.36.2Higher
1C2.311.75Less
1D1.31.51.34.1Less
2E1.722.46.1Same
2F241.57.5Higher
2G3.41.72.27.3Higher
2H12.325.3Less
3I1.51.32.45.2Less
3J21.714.7Less
3K42.42.48.8Higher
3L1.74.728.4Higher

 

I'm sure there's more elegant ways of achieving the same outcome but hopefully that helps 🙂

Anonymous
Not applicable

I find having 3 columns for Factor pretty awkward, but... here are some ideas to get you started?

 

Total Customers = COUNTROWS(MyTable)

Total Factor := SUMX(MyTable, MyTable[Factor 2014] + MyTable[Factor 2015] + MyTable[Factor 2016])

E Factor := CALCULATE([Total Factor], MyTable[Clientes] = "E")

Low Customers := CALCULATE([Total Customers], FILTER(MyTable, [Total Factor] < [E Factor])

High Customers := CALCULATE([Total Customers], FILTER(MyTable, [Total Factor] > [E Factor])

vanessafvg
Super User
Super User

@vmsouza30 not sure if i understand your requirement, but maybe something like the earlier function can work?

 

http://tinylizard.com/dax-earlier-function/

 

there is also a later function.  If you can work out a pattern with it.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

I think you are going to want to reshape your data.  Likely you will find it easier to deal with a single factor column, and a separate year column.  (You can use the Unpivot functionality in Edit Queries for this).

 

I'm also skeptical that you are going to want comma separated values like that...

In this case I do not have to worry about separating the factor in date, here could be Factor1, factor2, etc.
My problem is to have the reference index of a client and do the calculations, as explained above.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors