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
dla005
Helper I
Helper I

Sum Value if it meets 2 criteria/filters

Hi, 

 

Is there a DAX measure that if it meets the 2 filter restriction then to sum up the value column? Below is what my data looks like and the 2 restriction are, Table Recieved date > = Recieved Date and Table Recieved Date < Complete Date.  Table Recieved Date is basically Matrix visualizations with Recieved Date as the rows. I also already created a Date table using calendar auto and linking it to my query through Received Date.

 

My goal is to capture any inventory that is not completed by the end of the month. Thank you so much for your help!

 

Received Date   Complete date  Value  
march march0
march june1
march null1
marchapril1
apriljuly1
mayjune1
junejune0
julyjuly0
1 ACCEPTED SOLUTION

Thanks for clarifying.  I thought the Value column was to show which rows to keep.  In any case, here is an expression that gets your desired results.  FYI That I duplicated your Received Date column and made it into a Date column so this expression would work.

 

New Measure =
VAR __thisdate =
    MIN ( 'Table'[Received Date   ] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value  ] ),
        ALL ( 'Table' ),
        'Table'[Received Date   ] <= __thisdate,
        OR (
            'Table'[Complete date  ] > __thisdate,
            ISBLANK ( 'Table'[Complete date  ] )
        )
    )

If needed, here is the M code to transform your example data.

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wyk0sSs5QUNKBMIC0gVKsDpJwVmleKpAyRBXNK83JQRUF8hILijIRojBeVmlOJZLSSnQzoRwoZQAVy6lEaAWKxQIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Received Date " = _t, #"Complete date " = _t, #"Value " = _t]),
#"Duplicated Column" = Table.DuplicateColumn(Source, "Received Date ", "Received Date - Copy"),
#"Added Suffix" = Table.TransformColumns(#"Duplicated Column", {{"Received Date ", each _ & " 2020", type text}}),
#"Added Suffix1" = Table.TransformColumns(#"Added Suffix", {{"Complete date ", each _ & " 2020", type text}}),
#"Changed Type" = Table.TransformColumnTypes(#"Added Suffix1",{{"Received Date ", type date}, {"Complete date ", type date}, {"Value ", Int64.Type}}),
#"Replaced Errors" = Table.ReplaceErrorValues(#"Changed Type", {{"Complete date ", null}})
in
#"Replaced Errors"

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

7 REPLIES 7
dla005
Helper I
Helper I

Hi, 

 

Is there a DAX measure that if it meets the 2 filter restriction then to sum up the value column? Below is what my data looks like and the 2 restriction are, Table Recieved date > = Recieved Date and Table Recieved Date < Complete Date.  Table Recieved Date is basically Matrix visualizations with Recieved Date as the rows. I also already created a Date table using calendar auto and linking it to my query through Received Date.

 

My goal is to capture any inventory that is not completed by the end of the month. Thank you so much for your help!

 

Received Date       Complete Date       Value      
march march0
march june1
march null1
apriljuly1
mayjune1
junejune0
julyjuly0

Hi @dla005 ,

 

I'm having some confusion in understanding your first requirement:

 

Table Recieved date >= Recieved Date 

 

How can you have a line value tha the receveid date is higher than the received date? (I'm looking at indivual line values).

 

On the data below can you share what would be the calculation for the months?

Using the following measure:

 

Measure =
CALCULATE (
    SUM ( 'Table'[Value] );
    FILTER (
        ALL ( 'Table'[Complete Date] );
        'Table'[Complete Date] >= MAX ( CalendarTable[Date] )
            || 'Table'[Complete Date] = BLANK ()
    )
)

 

 

I'm getting this values:

March - 2

April -1

May - 1

 

Are this values correct?


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



mahoneypat
Employee
Employee

From your example data (which may be oversimplified), this expression should give you the # of rows that meet both criteria.

 

Rows Meeting Both =
COUNTROWS ( FILTER ( Table, Table[Complete date] <> Table[Received date] ) )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi @mahoneypat,

 

I tried using the DAX you recommended and it doesnt work because I think it doesnt take into account the value column? 

 

What i was hoping the DAX would return is the goal/correct value below. For example, May should return 4 because there was 6 "items" that was recieved in May and before (4 in Mar, 1 in Apr, and 1 in May) and 2 of which was completed before the end of May, so the total ending inventory for May that is still open is 4. If the item is recieved in May and compelted in May thata count as 0. (Complete date > Recieved Date).

 

Goal

Received Date     #
March3
April3
May4
June2
July 

Thanks for clarifying.  I thought the Value column was to show which rows to keep.  In any case, here is an expression that gets your desired results.  FYI That I duplicated your Received Date column and made it into a Date column so this expression would work.

 

New Measure =
VAR __thisdate =
    MIN ( 'Table'[Received Date   ] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value  ] ),
        ALL ( 'Table' ),
        'Table'[Received Date   ] <= __thisdate,
        OR (
            'Table'[Complete date  ] > __thisdate,
            ISBLANK ( 'Table'[Complete date  ] )
        )
    )

If needed, here is the M code to transform your example data.

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wyk0sSs5QUNKBMIC0gVKsDpJwVmleKpAyRBXNK83JQRUF8hILijIRojBeVmlOJZLSSnQzoRwoZQAVy6lEaAWKxQIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Received Date " = _t, #"Complete date " = _t, #"Value " = _t]),
#"Duplicated Column" = Table.DuplicateColumn(Source, "Received Date ", "Received Date - Copy"),
#"Added Suffix" = Table.TransformColumns(#"Duplicated Column", {{"Received Date ", each _ & " 2020", type text}}),
#"Added Suffix1" = Table.TransformColumns(#"Added Suffix", {{"Complete date ", each _ & " 2020", type text}}),
#"Changed Type" = Table.TransformColumnTypes(#"Added Suffix1",{{"Received Date ", type date}, {"Complete date ", type date}, {"Value ", Int64.Type}}),
#"Replaced Errors" = Table.ReplaceErrorValues(#"Changed Type", {{"Complete date ", null}})
in
#"Replaced Errors"

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you @mahoneypat  what you provided works perfectly!! I been trying to figure this out for like a week! One quick question, why did you use Min('Table'[Received Date]) and why did you use the statement below? I would assume it should be an and statement? Again, Thank you so much for your help!

 

 OR (

            'Table'[Complete date  ] > __thisdate,

            ISBLANK ( 'Table'[Complete date  ] )

 

 

@amitchandak  Thank you for the suggestion. I will look over it as I am still learning Power BI so anything is helpful!

 

 

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.