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

Last Resort Question & Desperate - Advanced Power BI Fixed Calculations for Categories

Hi All,

 

This is my fourth post regarding this topic wihtout success and my last attempt to try to get help from the community to solve it. It was easier to do in Tableau with Fixed Calculations at various levels, but I am STRUGGLING to do it in Power BI. This report has taken me a little over a year, and I'm in the same place.

 

There are five categories these customers - items should go in, and I have provided a sample that contains each in theory. The end-user wants to have this dynamic

 

Current Period is whatever the user selects using the date table

The previous Period is that range - 365

 

Customer Start: Customer Create Date is within the user's selected window. In this case, 1/1/2021 - 1/31/2021

Customer Stop - Customer Create Date is outside the current Period, and there are no transactions at a CUSTOMER level in the current Period. I created the Customer Volume column in SQL to try to aggregate this and ignore the items since DAX wasnt working. This means If I am customer A and I bought items 1,2,3 but no items in the current period.

 

Product Start - Customer Create Date is outside the current Period, and there are no transactions in the previous Period, but there are some at the Customer Item level in the current Period. This means I bought 0 items in the previous period but did buy some in the filtered period and am an existing customer

Product Stop - Customer Create Date is outside the current Period, and there are no transactions in the current Period, but there are some at the Previous Item Level in the previous Period. This means If I am customer A and I bought items 1,2,3 but bought items 1,2 in the current period, Item 3 would be Product Stop.

 

Volume - Transactions exist in the current and previous period. (asks as the "Else")

 

Based on my sample data. The categorization should be as follows. As I mentioned, I have spent hundreds of hours on this report trying to replicate something I created in Tableau and even mixing in SQL to get the Volume at the Customer Category since Power BI can't replicate the fixed calculations, I just simply hit a roadblock and can't do anymore.

 

Any help would be greatly appreciated, and I know there are more advanced people than me in DAX, and I am hoping they can help out.

 

The sample workbook is below:

 

https://drive.google.com/file/d/1MP2XoNaYF-CyrMHXuNP4hiRw3aIx0nLm/view?usp=sharing

 

 

cust_numitemDriver
80KC4401062X60X60Product Stop
813800RF125A0400Product Stop
813850RF062A0100Product Stop
813850RF062B0600Product Stop
813860FF062A0150Product Stop
813860FF062A0250Product Start
813860FF062A0300Product Stop
813860FF062A0400Product Start
813860RF062A0200Product Start
813860RF062A0250Product Start
813860RF062A0300Volume
813860RF062A0400Product Start
813860RF062A0500Product Start
813860RF062A0600Product Start
813860RF062A0800Product Start
813860RF062A1000FCProduct Start
813860RF062A1400FCProduct Start
813860RF062A1600FCProduct Start
813860RF125A1600FCProduct Stop
813880FF062A0150FCProduct Stop
813880FF062A0200FCProduct Start
813880FF062A0300FCProduct Stop
813880FF062A0400FCProduct Start
813880FF062A0600FCProduct Start
813880FF062A0800FCProduct Start
813880FF062A1200FCProduct Start
813880FF125A0150FCProduct Stop
813880FF125A0600FCProduct Start
813880FF125A1200FCProduct Stop
813880FF125B0300FCProduct Stop
813880RF125A0400FCProduct Start
813880RF125A1600FCProduct Stop
813G3000FF062A0600Product Stop
813G3000FF062A0800Product Stop
813G3000FF062A1000Product Stop
813G3000FF062A1200Product Stop
813G3000FF062A1400Product Stop
813G3000FF062B0600Product Stop
813G3000FF062B0800Product Stop
813G3000FF062B1000Product Stop
813G3000FF062B1200Product Stop
813G3000FF062B1400Product Stop
83TCNA400Product Stop
83TLSM100SPProduct Start
12PUL007X14X22Customer Stop
302547ACustomer Start
302547DCustomer Start
169913THE075CCustomer Start

 

1 ACCEPTED SOLUTION
AlB
Super User
Super User

Hi @Anonymous 

1. The expected result seems to be wrong for

       - Customer 8, Item 13880FF062A0300FC

       - Customer 30

2. If you want a dynamic period, you'll need to do this through a measure, not a calculated column. 

3. The DAX logic is not overly complicated, only a bit cumbersome to write. Create a measure as below. See it all at work in the attached file.

4. As a side comment, I would strongly discourage the use of the Auto Date/Time option.

 

 

 

 

DriverMeasure = 
VAR createdDate_ = DATEVALUE ( SELECTEDVALUE ( 'Invoice Variance'[createdate] ) ) //Watch out, createddate column actually of DateTime type
VAR currentPeriod_ = DISTINCT ( 'Current Period'[Date] )
VAR previousPeriod_ = DATEADD ( 'Current Period'[Date], -1, YEAR )
VAR custTransCurrentPeriod_ =
    CALCULATE (
        COUNT ( 'Invoice Variance'[inv_date] ),
        TREATAS ( currentPeriod_, 'Invoice Variance'[inv_date] ),
        ALLEXCEPT ( 'Invoice Variance', 'Invoice Variance'[cust_num] )
    ) + 0
VAR itemTransPreviousPeriod_ =
    CALCULATE (
        COUNT ( 'Invoice Variance'[inv_date] ),
        TREATAS ( previousPeriod_, 'Invoice Variance'[inv_date] )
    ) + 0
VAR itemTransCurrentPeriod_ =
    CALCULATE (
        COUNT ( 'Invoice Variance'[inv_date] ),
        TREATAS ( currentPeriod_, 'Invoice Variance'[inv_date] )
    ) + 0
VAR createdInPeriod_ = createdDate_ IN currentPeriod_
RETURN
    SWITCH (
        TRUE (),
        createdInPeriod_, "Customer Start",
        NOT createdInPeriod_ && custTransCurrentPeriod_ = 0, "Customer Stop",
        itemTransPreviousPeriod_ = 0 && itemTransCurrentPeriod_ > 0, "Product Start",
        itemTransPreviousPeriod_ > 0 && itemTransCurrentPeriod_ = 0, "Product Stop",
        itemTransPreviousPeriod_ > 0 && itemTransCurrentPeriod_ > 0, "Volume"
    )

 

 

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

 

View solution in original post

1 REPLY 1
AlB
Super User
Super User

Hi @Anonymous 

1. The expected result seems to be wrong for

       - Customer 8, Item 13880FF062A0300FC

       - Customer 30

2. If you want a dynamic period, you'll need to do this through a measure, not a calculated column. 

3. The DAX logic is not overly complicated, only a bit cumbersome to write. Create a measure as below. See it all at work in the attached file.

4. As a side comment, I would strongly discourage the use of the Auto Date/Time option.

 

 

 

 

DriverMeasure = 
VAR createdDate_ = DATEVALUE ( SELECTEDVALUE ( 'Invoice Variance'[createdate] ) ) //Watch out, createddate column actually of DateTime type
VAR currentPeriod_ = DISTINCT ( 'Current Period'[Date] )
VAR previousPeriod_ = DATEADD ( 'Current Period'[Date], -1, YEAR )
VAR custTransCurrentPeriod_ =
    CALCULATE (
        COUNT ( 'Invoice Variance'[inv_date] ),
        TREATAS ( currentPeriod_, 'Invoice Variance'[inv_date] ),
        ALLEXCEPT ( 'Invoice Variance', 'Invoice Variance'[cust_num] )
    ) + 0
VAR itemTransPreviousPeriod_ =
    CALCULATE (
        COUNT ( 'Invoice Variance'[inv_date] ),
        TREATAS ( previousPeriod_, 'Invoice Variance'[inv_date] )
    ) + 0
VAR itemTransCurrentPeriod_ =
    CALCULATE (
        COUNT ( 'Invoice Variance'[inv_date] ),
        TREATAS ( currentPeriod_, 'Invoice Variance'[inv_date] )
    ) + 0
VAR createdInPeriod_ = createdDate_ IN currentPeriod_
RETURN
    SWITCH (
        TRUE (),
        createdInPeriod_, "Customer Start",
        NOT createdInPeriod_ && custTransCurrentPeriod_ = 0, "Customer Stop",
        itemTransPreviousPeriod_ = 0 && itemTransCurrentPeriod_ > 0, "Product Start",
        itemTransPreviousPeriod_ > 0 && itemTransCurrentPeriod_ = 0, "Product Stop",
        itemTransPreviousPeriod_ > 0 && itemTransCurrentPeriod_ > 0, "Volume"
    )

 

 

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

 

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.