Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Making a visual that pulls data from two tables

Hi, I want to use a visual to show the projected and actual sales of a product by quarter such as in Table C. My data sources would be Table A and B. I am new to powerBI and would be really grateful if anyone is able to help. Thank you.

 

Table A    
ProductProduct IDSales DateStock DateCategory
A126899/5/20204/5/20201
B785636/5/20205/29/20202
D876541/24/20204/22/20204
C768783/21/20203/25/20203
C768786/21/20209/12/20203
D876542/5/20202/24/20204
A126891/15/20202/23/20201
A1268912/7/202012/9/20201
B785639/29/20204/14/20202
C7687810/2/20207/12/20203
C768786/25/20202/25/20203
D876544/3/20209/9/20204
D8765411/25/20206/7/20204
C768782/24/20202/19/20203
A126894/5/20206/9/20201
B785632/26/202012/17/20202
B785633/16/20208/29/20202
.....
.....
.....
C768784/22/202010/12/20203

 

Table B  
ProductQuarterProjected
AQ110
AQ220
AQ310
AQ424
BQ134
BQ220
BQ310
BQ420
CQ123
CQ25
CQ315
CQ418
DQ117
DQ215
DQ330
DQ425

 

Output

Table C  
ProductQuarterProjectedActual
AQ11010
AQ22025
AQ31012
AQ42424
BQ13434
BQ22021
BQ31017
BQ42018
CQ12324
CQ256
CQ3157
CQ41823
DQ11716
DQ21513
DQ33035
DQ42526
  • Hi Anonymous 

    Try this, use the first three columns in tableB

    Then create this measure

    Actual =
    CALCULATE (
        COUNTROWS ( 'Table A' ),
        FILTER (
            ALL ( 'Table A' ),
            'Table A'[Product] = MIN ( 'Table B'[Product] )
                && QUARTER ( 'Table A'[Sales Date] )
                    = VALUE ( RIGHT ( MIN ( 'Table B'[Quarter] ), 1 ) )
        )
    )

    Result

     

     

    Best Regards,

    Community Support Team _Tang

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

2 Replies

  • Anonymous , In table one you can create Qtr based on any of the date

     

    example

    c

     

    Then you can create a combine key and join both tables

     

    Key = [Product] & "-" [QTR]

     

    you can not get data in visual together

     

    do in Power Query , new columns

    ="Q"& Number.ToText(Date.QuarterOfYear([sales Date]))

     

    In both tables

    "Q"& Number.ToText(Date.QuarterOfYear([sales Date]))

     

     

    merge two tables

     


    Append and merge : https://radacad.com/append-vs-merge-in-power-bi-and-power-query

  • v-xiaotang's avatar
    v-xiaotang
    Community Support

    Hi Anonymous 

    Try this, use the first three columns in tableB

    Then create this measure

    Actual =
    CALCULATE (
        COUNTROWS ( 'Table A' ),
        FILTER (
            ALL ( 'Table A' ),
            'Table A'[Product] = MIN ( 'Table B'[Product] )
                && QUARTER ( 'Table A'[Sales Date] )
                    = VALUE ( RIGHT ( MIN ( 'Table B'[Quarter] ), 1 ) )
        )
    )

    Result

     

     

    Best Regards,

    Community Support Team _Tang

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