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
Young_G_Han
Helper III
Helper III

A sum of sales that only the product sold in a different specific period

 Hi.

 

I have a problem with the dynamic two periods and the sum of sales.

 

My table is like...

 

Product     Q'ty      Period

A                1            a

B                2            a

C                1            b

A                2            b

A                1            c

 

For some reason, I have to get the sum of sales by two different periods.

 

With calculation...

Product      Sales in period a       Sales in period b

A                           1                                 2

B                           2

C                                                              1

Total                      3                                 3

 

I made this but I had to make another column only for the items that I sold during both a and b periods.

 

Product      Sales in period a       Sales in period b      %Growth

A                           1                                 2                       100%

B                           1                                                              0%

C                                                              1                           0%

Total                      3                                 3                          0%

 

 

But I want to make the table like this...

 

Product      Sales in period a       Sales in period b      %Growth

A                           1                                 2                       100%

Total                      1                                 2                       100%

 

and also need a card for the %Growth as 100%.

I can delete the items from the table with the 'filters' but I cannot use the 'filters' for a card.

 

1 ACCEPTED SOLUTION

Hi , @Young_G_Han 

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1675828699461.png

(2)I create two date table as two slicers , like this:

vyueyunzhmsft_1-1675828736472.png

(3)Then we need to create three measures to put on the visual:

Sales in period a = var _min_date = MIN('A SLicer'[Period A])
 var _max_date = MAX('A SLicer'[Period A])
 var _t = FILTER('Table' ,'Table'[ORD_OPEN_DATE]>= _min_date && 'Table'[ORD_OPEN_DATE]<= _max_date)
 return
 SUMX(_t ,[CUST_LINE_VALUE])
Sales in period b = var _min_date =MIN('B SLicer'[Period B])
 var _max_date = MAX('B SLicer'[Period B])
 var _t = FILTER('Table' ,'Table'[ORD_OPEN_DATE]>= _min_date && 'Table'[ORD_OPEN_DATE]<= _max_date)
 return
 SUMX(_t ,[CUST_LINE_VALUE])
%Growth = IF([Sales in period a] && [Sales in period b] , DIVIDE( [Sales in period b]-[Sales in period a] , [Sales in period a]) )

Then we can get first need:

vyueyunzhmsft_2-1675828786560.png

(4)We can create another measure to filter the blank in this visual:

Flag = IF([Sales in period a]<> BLANK() && [Sales in period b] <> BLANK() ,1,0)

Then we can configure the measure on the "Filter on this visual" ,then  the second need we can get:

vyueyunzhmsft_3-1675828857851.png

 

(5)In the end , we can create a measure in the card visual:

Measure in a Card = var _t= SUMMARIZE('Table','Table'[ITEM] , "Sales in a",[Sales in period a],"Sales in b",[Sales in period b])
var _t2= FILTER(_t,[Sales in period a]<> BLANK() && [Sales in period b]<> BLANK())
return
DIVIDE( SUMX(_t2,[Sales in period b])-SUMX(_t2,[Sales in period a]) , SUMX(_t2 ,[Sales in period a]))

Then we can meet your last need:

vyueyunzhmsft_4-1675828899736.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

6 REPLIES 6
danextian
Super User
Super User

Hi @Young_G_Han ,

 

You can create a calculated column to check whether a product has sales in both periods a and b

With sales in perios a and b = 
CALCULATE (
    SUM ( 'Table'[Qty] ),
    ALLEXCEPT ( 'Table', 'Table'[Product] ),
    'Table'[Period] = "a"
)
    <> BLANK ()
    && CALCULATE (
        SUM ( 'Table'[Qty] ),
        ALLEXCEPT ( 'Table', 'Table'[Product] ),
        'Table'[Period] = "b"
    )
        <> BLANK ()

.Please see sample pbix.










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

  Dear Danextian

 

Thank you for your help.

I created a column with the formula you informed me of.

 

But I have modified it below.

However, the new field has #ERROR as a value.

 

With sales in perios a and b =

Var PMAXDate = VALUES(PRI[Exp.Date])

Var PMINDate = VALUES(PRI[Act.Date])

Var SMAXDate = VALUES(SEC[Exp.Date])

Var SMINDate = VALUES(SEC[Act.Date])

return

CALCULATE (
    SUM (SalesDB[SYS_LINE_VALUE] ),
    ALLEXCEPT (SalesDB, SalesDB[ITEM] ),
    SalesDB[DATE] <= PMAXDate,
    SalesDB[DATE] >= PMINDate
)
    <> BLANK ()
    && CALCULATE (
        SUM(SalesDB[SYS_LINE_VALUE] ),
        ALLEXCEPT (SalesDB, SalesDB[ITEM] ),
        SalesDB[DATE] <= SMAXDate,
        SalesDB[DATE] >= SMINDate
    )
        <> BLANK ()
 
 
The Error message is...
A table of multiple values was supplied where a single value was expected.
 
I think this is caused by the period range. But I need multiple periods.
Can you advise?
Thank you in advance.

hi @Young_G_Han ,

 

The solution initially proposed was based on the sample data. Can you please post a sample data that actually represents your data?










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

  Dear Danextian

 

The following is the sample data.

And the period must be changed based on users' selection.

 

Period A: 2022-10-04 to 2023-02-07

Period B: 2020-01-02 to 2021-02-14

 

ITEM IDCUSTOMERCUST_LINE_VALUECust. CountryORD_OPEN_DATE
3601064A571.48USA2017-02-23 0:00
3601119A715.22USA2017-05-05 0:00
3601119A719.22USA2017-06-29 0:00
3601119A721.36USA2017-08-04 0:00
3601119A750.7USA2019-03-29 0:00
3601119A771.62USA2020-03-04 0:00
3601119A411.73USA2021-02-25 0:00
3601119A443.57USA2022-07-22 0:00
3601119A439.66USA2022-07-26 0:00
3601120A394.64USA2020-06-09 0:00
3601120A403.11USA2021-04-01 0:00
3601120A473.24USA2022-12-21 0:00
3601127A715.22USA2017-05-05 0:00
3601127A719.22USA2017-06-29 0:00
3601223A456.67USA2016-02-03 0:00
3601228A408.06USA2015-03-11 0:00
3601228A409.42USA2015-03-26 0:00
3601228A883.3USA2018-04-04 0:00
3601228A987.68USA2021-04-01 0:00
3601431A818.84USA2015-03-26 0:00
3601613A373.46USA2019-10-22 0:00
3601618A403.11USA2021-04-01 0:00
3601622A966.7USA2022-10-25 0:00
3602968A493.84USA2021-04-01 0:00
3604859A686.46USA2016-03-24 0:00
3604859A1378.32USA2018-01-30 0:00
3604859A723.09USA2019-06-19 0:00
3604859A1601.2USA2021-08-11 0:00
6181902A633.28USA2020-03-06 0:00
6181902A980.08USA2020-03-13 0:00
6341178A1110.38USA2020-12-22 0:00

Hi , @Young_G_Han 

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_0-1675828699461.png

(2)I create two date table as two slicers , like this:

vyueyunzhmsft_1-1675828736472.png

(3)Then we need to create three measures to put on the visual:

Sales in period a = var _min_date = MIN('A SLicer'[Period A])
 var _max_date = MAX('A SLicer'[Period A])
 var _t = FILTER('Table' ,'Table'[ORD_OPEN_DATE]>= _min_date && 'Table'[ORD_OPEN_DATE]<= _max_date)
 return
 SUMX(_t ,[CUST_LINE_VALUE])
Sales in period b = var _min_date =MIN('B SLicer'[Period B])
 var _max_date = MAX('B SLicer'[Period B])
 var _t = FILTER('Table' ,'Table'[ORD_OPEN_DATE]>= _min_date && 'Table'[ORD_OPEN_DATE]<= _max_date)
 return
 SUMX(_t ,[CUST_LINE_VALUE])
%Growth = IF([Sales in period a] && [Sales in period b] , DIVIDE( [Sales in period b]-[Sales in period a] , [Sales in period a]) )

Then we can get first need:

vyueyunzhmsft_2-1675828786560.png

(4)We can create another measure to filter the blank in this visual:

Flag = IF([Sales in period a]<> BLANK() && [Sales in period b] <> BLANK() ,1,0)

Then we can configure the measure on the "Filter on this visual" ,then  the second need we can get:

vyueyunzhmsft_3-1675828857851.png

 

(5)In the end , we can create a measure in the card visual:

Measure in a Card = var _t= SUMMARIZE('Table','Table'[ITEM] , "Sales in a",[Sales in period a],"Sales in b",[Sales in period b])
var _t2= FILTER(_t,[Sales in period a]<> BLANK() && [Sales in period b]<> BLANK())
return
DIVIDE( SUMX(_t2,[Sales in period b])-SUMX(_t2,[Sales in period a]) , SUMX(_t2 ,[Sales in period a]))

Then we can meet your last need:

vyueyunzhmsft_4-1675828899736.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

I referred to your pbix file and it is perfectly working.

Thank you so much!!!

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.