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
Anonymous
Not applicable

Linear Regression DAX Help

Table 1

DIMENTIONCodeSubDimentionGeneralQ
FoodF1Chicken 
FoodF2Chicken 
FoodF3Chicken 
FoodF0ChickenG1
GroceryG1Sweet 
GroceryG2Sweet 
GroceryG3Sweet 
GroceryG0SweetG1
LexuryL1Cereal 
LexuryL2 Cereal 
LexuryL0CerealG1
OptionalO1Meat 
OptionalO2Meat 
OptionalO3Meat 
OptionalO0MeatG1


Table2

IDVariable_codeOpinion
1Wine1
1F12
1F23
1F34
1F02
1G13
1G24
1G35
1G03
1L14
1L2 5
1L04
1O15
1O26
1O31
1O03
2Wine1
2F12
2F23
2F34
2F02
2G13
2G24
2G35
2G03
2L14
2L2 5
2L04
2O15
2O26
2O31
2O03
3Wine1
3F12
3F23
3F34
3F02
3G13
3G24
3G35
3G03
3L14
3L2 5
3L04
3O15
3O26
3O31
3O03
4Wine1
4F12
4F23
4F34
4F02
4G13
4G24
4G35
4G03
4L14
4L2 5
4L04
4O15
4O26
4O31
4O03
5Wine1
5F12
5F23
5F34
5F02
5G13
5G24
5G35
5G03
5L14
5L2 5
5L04
5O15
5O26
5O31
5O03
6Wine1
6F12
6F23
6F34
6F02
6G13
6G24
6G35
6G03
6L14
6L2 5
6L04
6O15
6O26
6O31
6O03
7Wine1
7F12
7F23
7F34
7F02
7G13
7G24
7G35
7G03
7L14
7L2 5
7L04
7O15
7O26
7O31
7O03


Measure 12 =
Part of the furmula where I have to do SUMX(X*Y), and Greg_Deckler submitted this solution:

VAR _table =
    SUMMARIZE ( ALL ( 'Table12' ), [ID] )
VAR _table1 =
    ADDCOLUMNS (
        _table,
        "_y"SUMX (
            FILTER (
                ALL ( 'Table12' ),
                [ID] = EARLIER ( [ID] )
                    && [Variable_Code] = "Wine"
            ),
            [Opinion]
        ),
        "_x"SUMX (
            FILTER (
                ALL ( 'Table12' ),
                [ID] = EARLIER ( [ID] )
                    && [Variable_Code] = "F0"      //ChickenGeneral
            ),
            [Opinion]
        )
    )
VAR _table2 =
    ADDCOLUMNS ( _table1"__product", [x] * [y] )
RETURN
    SUMX ( _table2, [product] )
 
The thing is, in ("[Variable_Code] = "F0"), that "F0" have to change with a filter with any general question (F0, G0, L0, O0).
How can I filtar that??
 
I have tryed with RELATED[Variable Code] = Table2[Code] and getting the filter in the sheet with "Image" column, like this: 
ChickenGeneral
SweetGeneral
CerealGeneral
MeatGeneral
 
I supposse to select one of this, and the option should change the result
1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

You could try this way:

Step1:

Create the relationship between these two tables by 

1.JPG

Step2:

Use this formula to add a measure

Measure = 
VAR _table =
    SUMMARIZE ('Table12' , [ID] ,[Variable_code],[Opinion])
VAR _table1 =
    ADDCOLUMNS (
        _table,
        "y", SUMX (
            FILTER (
               ALL( 'Table12') ,
                [ID] = EARLIER ( [ID] )
                    && [Variable_Code] = "Wine"
            ),
            [Opinion]
        )
    )
VAR _table2 =
    ADDCOLUMNS ( _table1, "product", [Opinion] * [y] )
RETURN
    SUMX ( _table2, [product] )

Result:

2.JPG

 

and here is pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
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

4 REPLIES 4
Anonymous
Not applicable

Good day guys... I have this two tables: 

 

Table1

ID

Variable_codeOpinion
1Wine1
1

M1

2
1V23
1C14
1G35
1F06
2Wine5
2M24
2V03
2C42
2G01
2F46
3Wine4
3M13
3V02
3C31
3G26
3F65
4Wine3
4M02
4V01
4C06
4G25
4F04
5Wine2
5M11
5V06
5C05
5G04
5F03
6Wine1
6M16
6V05
6C14
6G03
6F32
7Wine1
7M12
7V33
7C04
7G35
7F06

 

Table 2
DIMENTIONCodeSubDimentionGeneralQ
ChickenF1Chicken1 
ChickenF2Chicken2 
ChickenF3Chicken3 
ChickenF4Chicken4 
ChickenF5Chicken5 
ChickenF6Chicken6 
ChickenF0ChickenGeneral1
GroceryG1Grocery1 
GroceryG2Grocery2 
GroceryG3Grocery3 
GroceryG4Grocery4 
GroceryG5Grocery5 
GroceryG6Grocery6 
GroceryG0GroceryGeneral1
CerealL1Cereal1 
CerealL2 Cereal2 
CerealL3Cereal3 
CerealL4Cereal4 
CerealL5Cereal5 
CerealL6Cereal6 
CerealL0CerealGeneral1
VegetablesB1Vegetable1 
VegetablesB2Vegetable2 
VegetablesB3Vegetable3 
VegetablesB4Vegetable4 
VegetablesB0VegetableGeneral1
MeatO1Meat1 
MeatO2Meat2 
MeatO3MeatGeneral1

 

One part of the formula is sumx(XY), where "Y" is the opinion if "wine".

"X" have to variate among the opinion of "meat", "chicken", "candy", etc. So "X" have to be like a filter.

 

Greg_Deckler submitted this solution:

 

Measure 12 =
VAR __table =
    SUMMARIZE ( ALL ( 'Table12' ), [ID] )
VAR __table1 =
    ADDCOLUMNS (
        __table,
        "__y"SUMX (
            FILTER (
                ALL ( 'Table12' ),
                [ID] = EARLIER ( [ID] )
                    && [Variable_Code] = "Wine"
            ),
            [Opinion]
        ),
        "__x"SUMX (
            FILTER (
                ALL ( 'Table12' ),
                [ID] = EARLIER ( [ID] )
                    && [Variable_Code] = "F0"      //ChickenGeneral
            ),
            [Opinion]
        )
    )
VAR __table2 =
    ADDCOLUMNS ( __table1"__product", [__x] * [__y] )
RETURN
    SUMX ( __table2, [__product] )
 
 
I do not have problems with "Wine" because that is the "Y" in linear regression. Instead, I need to filter the other part of the table: "Chicken", "Meat", "Candy", etc.
 

 

Where "Chiken", "Meat", "Candy", etc, are my principal questions (General Questions).

 

So, in the part of the formula

[Variable_Code] = "F0", I need to change with a filter in the sheet, the other codes.

 

I have tryed with HASONVALUE, SELECTED VALUE, RELATED[Nombre de la variable] = TableN[Code], and nothing has happened....

Anonymous
Not applicable

Every product have a code, but is not filtering everyone in the results

v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

You could try this way:

Step1:

Create the relationship between these two tables by 

1.JPG

Step2:

Use this formula to add a measure

Measure = 
VAR _table =
    SUMMARIZE ('Table12' , [ID] ,[Variable_code],[Opinion])
VAR _table1 =
    ADDCOLUMNS (
        _table,
        "y", SUMX (
            FILTER (
               ALL( 'Table12') ,
                [ID] = EARLIER ( [ID] )
                    && [Variable_Code] = "Wine"
            ),
            [Opinion]
        )
    )
VAR _table2 =
    ADDCOLUMNS ( _table1, "product", [Opinion] * [y] )
RETURN
    SUMX ( _table2, [product] )

Result:

2.JPG

 

and here is pbix file, please try it.

 

Best Regards,

Lin

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

Image is a column where:

 

IF( GeneralQ = 1 , SubDimention , BLANK() ), so it has ChickenG, SweetG, CerealG, MeatG

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.