Forum Discussion
How to get value and differentiate into 2 category / Measure
- 3 years ago
Hi, RanHo
Follow these steps
Step 1: Filter by Month and Year
If you have a date column in your dataset, you can create a slicer for month and year in Power BI. To do this:
- Go to the "Fields" pane.
- Drag the date field into the "Values" box of a slicer visual.
- In the slicer visual, click on the down arrow in the "Values" box and select "Month" or "Year". This will give you a slicer that you can use to filter your data by month or year.
Step 2: Differentiate between two categories (0-90 days and 90 days above)
Create a new column that calculates the difference between the current date and the product date. You can use the DATEDIFF function for this:
Days Difference = DATEDIFF(YourTable[Product Date], TODAY(), DAY)
Step 3: Classify as "WITHIN DATE" or "EXPIRED"
Create another new column that uses the "Days Difference" column to determine whether a product falls within the "0-90 days" category or the "90 days above" category:
Category = IF(YourTable[Days Difference] <= 90, "WITHIN DATE", "EXPIRED")
Hope this helps.
- 3 years ago
RanHo Good to know it worked.
Assuming that you have a unique identifier for each product that is shared between YourDataTable and CollectedPaidTable (e.g., ProductID), you can create a relationship between these two tables based on this identifier.
try this
Date_Label =
VAR IsPaid =
NOT(ISBLANK(
RELATED(CollectedPaidTable.ProductID)
))
RETURN
SWITCH(
TRUE(),
AND(DATEDIFF(YourDataTable.ProductDate, TODAY(), DAY) <= 90, IsPaid), "WITHIN DATE",
AND(DATEDIFF(YourDataTable.ProductDate, TODAY(), DAY) > 90, IsPaid), "WITHIN DATE",
AND(DATEDIFF(YourDataTable.ProductDate, TODAY(), DAY) <= 90, NOT(IsPaid)), BLANK(),
AND(DATEDIFF(YourDataTable.ProductDate, TODAY(), DAY) > 90, NOT(IsPaid)), "EXPIRED",
BLANK() // default
)Please replace YourDataTable, ProductDate, CollectedPaidTable, and ProductID with your actual table names and column names.
Hi, RanHo
Follow these steps
Step 1: Filter by Month and Year
If you have a date column in your dataset, you can create a slicer for month and year in Power BI. To do this:
- Go to the "Fields" pane.
- Drag the date field into the "Values" box of a slicer visual.
- In the slicer visual, click on the down arrow in the "Values" box and select "Month" or "Year". This will give you a slicer that you can use to filter your data by month or year.
Step 2: Differentiate between two categories (0-90 days and 90 days above)
Create a new column that calculates the difference between the current date and the product date. You can use the DATEDIFF function for this:
Days Difference = DATEDIFF(YourTable[Product Date], TODAY(), DAY)
Step 3: Classify as "WITHIN DATE" or "EXPIRED"
Create another new column that uses the "Days Difference" column to determine whether a product falls within the "0-90 days" category or the "90 days above" category:
Category = IF(YourTable[Days Difference] <= 90, "WITHIN DATE", "EXPIRED")
Hope this helps.
- RanHo3 years ago
Helper V
rubayatyasmin thanks! It worked! Accepted as Solution
But I have another aditional column called COLLECTED/PAID TABLE : all paid products is here/counted on this table. So
If the product is <=90days , and it's in the PAID table then result = WITHIN DATE
If the product is >90days , and it's in the PAID table then result = WITHIN DATE
If the product is <=90days , and it's NOT in the PAID table then result = BLANK
If the product is >90days , and it's NOT in the PAID table then result = EXPIRED
Is this possible?
Many thanks!!- rubayatyasmin3 years ago
Community Champion
RanHo Good to know it worked.
Assuming that you have a unique identifier for each product that is shared between YourDataTable and CollectedPaidTable (e.g., ProductID), you can create a relationship between these two tables based on this identifier.
try this
Date_Label =
VAR IsPaid =
NOT(ISBLANK(
RELATED(CollectedPaidTable.ProductID)
))
RETURN
SWITCH(
TRUE(),
AND(DATEDIFF(YourDataTable.ProductDate, TODAY(), DAY) <= 90, IsPaid), "WITHIN DATE",
AND(DATEDIFF(YourDataTable.ProductDate, TODAY(), DAY) > 90, IsPaid), "WITHIN DATE",
AND(DATEDIFF(YourDataTable.ProductDate, TODAY(), DAY) <= 90, NOT(IsPaid)), BLANK(),
AND(DATEDIFF(YourDataTable.ProductDate, TODAY(), DAY) > 90, NOT(IsPaid)), "EXPIRED",
BLANK() // default
)Please replace YourDataTable, ProductDate, CollectedPaidTable, and ProductID with your actual table names and column names.
- RanHo3 years ago
Helper V
rubayatyasmin Thanks a lot! It's actually worked.