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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
DJSwezey
Helper I
Helper I

Showing Counties that had Changes month to month

DJSwezey_0-1697470580598.png

 

I have a table that determines whether or not a county is an Optimal choice for a campaign my company is working on.

I need to create a column/measure that shows if there was an "Optimal" change for the same county in the same state from the previous month. Anything that remains the same be labeled as 'none', from a yes to a no labeled as "Yes to No" and anything from a no to yes labeled as "No to Yes".

Something similar to this: 

DJSwezey_1-1697470770293.png

 

The data will continue to change each month as the data source is a folder that contains a new excel file for each months data.

 

Any help would be greately appreciated!

 

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @DJSwezey 

You can try the following measure

Measure =
VAR a =
    MAXX (
        FILTER (
            ALLSELECTED ( Campaign ),
            [State]
                IN VALUES ( Campaign[State] )
                    && [Country]
                        IN VALUES ( Campaign[Country] )
                            && [Date] < SELECTEDVALUE ( Campaign[Date] )
        ),
        [Date]
    )
VAR b =
    MAXX (
        FILTER (
            ALLSELECTED ( Campaign ),
            [State]
                IN VALUES ( Campaign[State] )
                    && [Country]
                        IN VALUES ( Campaign[Country] )
                            && [Date] = a
        ),
        [Optimal]
    )
RETURN
    SWITCH (
        TRUE (),
        b = BLANK (), "N/A",
        SELECTEDVALUE ( Campaign[Optimal] ) = B, "None",
        b & " " & "to" & " "
            & SELECTEDVALUE ( Campaign[Optimal] )
    )

Output

vxinruzhumsft_0-1697613535098.png

 

Best Regards!

Yolo Zhu

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
v-xinruzhu-msft
Community Support
Community Support

Hi @DJSwezey 

You can try the following measure

Measure =
VAR a =
    MAXX (
        FILTER (
            ALLSELECTED ( Campaign ),
            [State]
                IN VALUES ( Campaign[State] )
                    && [Country]
                        IN VALUES ( Campaign[Country] )
                            && [Date] < SELECTEDVALUE ( Campaign[Date] )
        ),
        [Date]
    )
VAR b =
    MAXX (
        FILTER (
            ALLSELECTED ( Campaign ),
            [State]
                IN VALUES ( Campaign[State] )
                    && [Country]
                        IN VALUES ( Campaign[Country] )
                            && [Date] = a
        ),
        [Optimal]
    )
RETURN
    SWITCH (
        TRUE (),
        b = BLANK (), "N/A",
        SELECTEDVALUE ( Campaign[Optimal] ) = B, "None",
        b & " " & "to" & " "
            & SELECTEDVALUE ( Campaign[Optimal] )
    )

Output

vxinruzhumsft_0-1697613535098.png

 

Best Regards!

Yolo Zhu

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

 

DJSwezey
Helper I
Helper I

I have tried the following logic, but am getting n/a for everything. 

Optimal Changes = 
VAR CurrentState = 'Campaign'[State]
VAR CurrentCounty = 'Campaign'[County]
VAR CurrentMonth = 'Campaign'[Month]
VAR CurrentYear = 'Campaign'[Year]
VAR PreviousMonth = 
    CALCULATE(
        MAX('Campaign'[Month]),
        FILTER('Campaign', 
            'Campaign'[State] = CurrentState &&
            'Campaign'[County] = CurrentCounty &&
            'Campaign'[Year] = CurrentYear - 1
        )
    )
VAR CurrentOptimal = 'Campaign'[Optimal]
VAR PreviousOptimal = 
    CALCULATE(
        MAX('Campaign'[Optimal]),
        FILTER('Campaign',
            'Campaign'[State] = CurrentState &&
            'Campaign'[County] = CurrentCounty &&
            'Campaign'[Month] = PreviousMonth &&
            'Campaign'[Year] = CurrentYear - 1
        )
    )
RETURN
    IF(
        ISBLANK(PreviousOptimal), "n/a",
        IF(CurrentOptimal = PreviousOptimal, "None",
            IF(CurrentOptimal = "Yes", "No to Yes", "Yes to No")
        )
    )

In power query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUYpMLQaSlvqG+kYGRsZKsTrRSk5AAb98dFFnrKKOMFFDA3QjICajijvjEEcYY4jDGEOsbkESjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [County = _t, Optimal = _t, Date = _t]),
    tbl = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    tbl1 = Table.AddIndexColumn(tbl, "Index", 0, 1, Int64.Type),
    tbl2 = Table.Group(tbl1, {"County"}, {{"All", each Table.AddIndexColumn(Table.Sort(_,{{"Date", Order.Ascending}}), "Index1") }}),
    tbl3 = Table.TransformColumns(tbl2, {{"All", each Table.AddColumn(_, "Change", 
        (x)=> let current = x[Optimal], prior = _[Optimal]{x[Index1] - 1} in try if current = prior then "None" else prior & " to " & current otherwise "N/A") }}),
    tbl4 = Table.Combine(tbl3[All]),
    tbl5 = Table.Sort(tbl4,{{"Index", Order.Ascending}}),
    Result = Table.RemoveColumns(tbl5,{"Index", "Index1"})
in
    Result

 

Works flawlessly 👍

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors