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
nabullock
Frequent Visitor

Counts not working in a measure.

I am able to calculate the difference between two columns, but am not able to count those results.   I have a single table that list values and I need to count the number of increases and decreses, beyond a %, within a time period.  I am able to Return "Diff" to a table visual and I need to cont those values as below.  

 

 

 

 

Diff30CTest = 

VAR First30W = 

    CALCULATE(
        MIN(AllWeights[Date]),
        FILTER(
            AllWeights,
            AllWeights[Date] >= [sDateLess30] &&
            AllWeights[Date] <= [selectDate] &&
            AllWeights[ClientId] = SELECTEDVALUE(AllWeights[ClientId])
        )
    )

VAR FirstValue =
    CALCULATE(
        MIN(AllWeights[Value]),
        FILTER(
            AllWeights,
            AllWeights[ManPK] = MINX(
                FILTER(
                    AllWeights,
                    AllWeights[Date] = First30W &&
                    AllWeights[ClientId] = SELECTEDVALUE(AllWeights[ClientId])
                ),
                AllWeights[ManPK]
            )
        )
    )

VAR Last30W = 
    CALCULATE(
        MAX(AllWeights[Date]),
        FILTER(
            AllWeights,
            AllWeights[Date] >= [sDateLess30] &&
            AllWeights[Date] <= [selectDate] &&
            AllWeights[ClientId] = SELECTEDVALUE(AllWeights[ClientId])
        )
    )

VAR LastValue =
    CALCULATE(
        MAX(AllWeights[Value]),
        FILTER(
            AllWeights,
            AllWeights[ManPK] = MAXX(
                FILTER(
                    AllWeights,
                    AllWeights[Date] = Last30w &&
                    AllWeights[ClientId] = SELECTEDVALUE(AllWeights[ClientId])
                ),
                AllWeights[ManPK]
            )
        )
    )
VAR CompareFisrtToLast = IF([Last30W] <> [First30W],DIVIDE(([Last30W]-[First30W]),[First30W]),BLANK())
VAR Diff = If(ISBLANK([First30W]),BLANK(),CompareFisrtToLast)
VAR DiffAbove5Percent = IF(Diff > 0.05, 1, 0)
VAR DiffBelowNeg5Percent = IF(Diff < -0.05, 1, 0)
RETURN

 

 

 

 

I have tried bothe CountX and SUMX ..

So I think that my issue is that "Diff" is returning a rows and I am trying to count those, but DAX expect to count the rows of a table. 

 

 
5 REPLIES 5
v-shex-msft
Community Support
Community Support

HI @nabullock,

According to your description, it seems like common multiple date fields analysis requirement. For this scenario, you can take a look at the Greg’s blog ‘start date’, ‘end date’ part if helps:

Before You Post, Read This: start/end date 
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

I don't believe that it is an issue with the dates becuse I am able to correctly show value differents (DIFF30)  between the first value (First30W) and the last value (Last30W) within the date range.  I just need to count those.  If I needed to count those that were +/- 4%, in the table below, it would be 3, 2 are a loss and there is 1 gain. 

nabullock_1-1683578534626.png

 

 

Hi @nabullock,

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

ManPKClientIdDateValue
6062977-4/10/2023 9:02:31 AM60629774/10/2023 9:02:31 AM146.6
6062977-4/9/2023 6:23:00 AM60629774/9/2023 6:23:00 AM147.6
6218981-4/10/2023 8:40:00 AM62189814/10/2023 8:40:00 AM222
5708571-4/9/2023 2:32:20 PM57085714/9/2023 2:32:20 PM178
6476371-4/9/2023 1:59:00 PM64763714/9/2023 1:59:00 PM190
4135433-4/10/2023 1:46:18 PM41354334/10/2023 1:46:18 PM165.6
6927085-4/10/2023 4:01:18 PM69270854/10/2023 4:01:18 PM212.8
5311211-4/10/2023 12:25:29 PM53112114/10/2023 12:25:29 PM114
6927085-4/9/2023 2:27:18 PM69270854/9/2023 2:27:18 PM214.8
4919777-4/10/2023 1:39:00 PM49197774/10/2023 1:39:00 PM138.2
902441-4/9/2023 11:07:00 AM9024414/9/2023 11:07:00 AM170.3
75093-4/10/2023 12:26:00 PM750934/10/2023 12:26:00 PM152.1
117631-4/10/2023 3:41:44 PM1176314/10/2023 3:41:44 PM191.4
5445896-4/9/2023 12:40:07 PM54458964/9/2023 12:40:07 PM90.6
5870295-4/10/2023 1:38:00 PM58702954/10/2023 1:38:00 PM150
1156178-4/10/2023 8:26:00 AM11561784/10/2023 8:26:00 AM134.8
6447938-4/10/2023 1:59:00 PM64479384/10/2023 1:59:00 PM157.2
2326074-4/10/2023 9:49:00 AM23260744/10/2023 9:49:00 AM89.8
5541675-4/9/2023 12:44:00 PM55416754/9/2023 12:44:00 PM162.6
2665577-4/10/2023 9:32:00 AM26655774/10/2023 9:32:00 AM146.2
217101-4/10/2023 2:29:00 PM2171014/10/2023 2:29:00 PM122.1
3874130-4/10/2023 1:46:00 PM38741304/10/2023 1:46:00 PM87
6875632-4/10/2023 12:59:26 PM68756324/10/2023 12:59:26 PM136.6
6875632-4/9/2023 1:36:28 PM68756324/9/2023 1:36:28 PM136.2
1859058-4/10/2023 10:40:51 AM18590584/10/2023 10:40:51 AM68.8
1755831-4/10/2023 12:30:00 PM17558314/10/2023 12:30:00 PM103.4
1755831-4/9/2023 12:29:00 PM17558314/9/2023 12:29:00 PM102.6
6588919-4/9/2023 8:25:00 AM65889194/9/2023 8:25:00 AM149
651941-4/10/2023 4:21:00 PM6519414/10/2023 4:21:00 PM231.3
6817428-4/9/2023 11:42:00 AM68174284/9/2023 11:42:00 AM180
6817428-4/9/2023 11:38:00 AM68174284/9/2023 11:38:00 AM180
73253-4/10/2023 6:51:00 AM732534/10/2023 6:51:00 AM176
73253-4/9/2023 3:37:50 PM732534/9/2023 3:37:50 PM174.6
1235954-4/10/2023 9:23:00 AM12359544/10/2023 9:23:00 AM129.4
3023295-4/9/2023 1:38:42 PM30232954/9/2023 1:38:42 PM206
310659-4/10/2023 1:39:00 PM3106594/10/2023 1:39:00 PM154.2
4909727-4/10/2023 1:39:00 PM49097274/10/2023 1:39:00 PM198.1
39304-4/9/2023 12:50:00 PM393044/9/2023 12:50:00 PM153.2
5870295-4/9/2023 11:07:00 AM58702954/9/2023 11:07:00 AM150.1
3991466-4/9/2023 11:07:00 AM39914664/9/2023 11:07:00 AM120.1
5031618-4/9/2023 11:07:00 AM50316184/9/2023 11:07:00 AM191.8
6043027-4/9/2023 8:12:31 AM60430274/9/2023 8:12:31 AM103
6043027-4/9/2023 8:00:00 AM60430274/9/2023 8:00:00 AM103
2620808-4/9/2023 3:21:47 PM26208084/9/2023 3:21:47 PM110
109874-4/9/2023 12:47:00 PM1098744/9/2023 12:47:00 PM202
5256861-4/10/2023 1:50:27 PM52568614/10/2023 1:50:27 PM114
6755073-4/10/2023 1:28:47 PM67550734/10/2023 1:28:47 PM140
3782332-4/9/2023 1:39:08 PM37823324/9/2023 1:39:08 PM142
3783573-4/10/2023 9:59:00 AM37835734/10/2023 9:59:00 AM180
1653374-4/10/2023 9:02:00 AM16533744/10/2023 9:02:00 AM163.8
3783573-4/9/2023 11:02:00 AM37835734/9/2023 11:02:00 AM186
4626363-4/9/2023 1:36:08 PM46263634/9/2023 1:36:08 PM173.4
6679851-4/10/2023 5:51:29 PM66798514/10/2023 5:51:29 PM213
1617436-4/10/2023 9:29:02 AM16174364/10/2023 9:29:02 AM137
1617436-4/9/2023 1:48:23 PM16174364/9/2023 1:48:23 PM137
6218981-4/9/2023 8:38:00 AM62189814/9/2023 8:38:00 AM220
6655103-4/10/2023 9:20:00 AM66551034/10/2023 9:20:00 AM176
6847152-4/9/2023 1:03:06 PM68471524/9/2023 1:03:06 PM123.1
6037649-4/9/2023 9:30:00 AM60376494/9/2023 9:30:00 AM132
6715213-4/10/2023 1:53:00 PM67152134/10/2023 1:53:00 PM184.2
4324338-4/10/2023 8:46:32 PM43243384/10/2023 8:46:32 PM146
6798498-4/10/2023 9:32:00 AM67984984/10/2023 9:32:00 AM150.9
6379466-4/9/2023 1:07:00 PM63794664/9/2023 1:07:00 PM130.6
6241398-4/10/2023 9:22:00 AM62413984/10/2023 9:22:00 AM236
6241398-4/9/2023 9:22:00 AM62413984/9/2023 9:22:00 AM236.4
5855751-4/10/2023 1:52:00 PM58557514/10/2023 1:52:00 PM116.8
6165827-4/10/2023 1:49:00 PM61658274/10/2023 1:49:00 PM122.6
5855751-4/10/2023 1:13:00 PM58557514/10/2023 1:13:00 PM116.8
6847152-4/10/2023 10:26:00 AM68471524/10/2023 10:26:00 AM124.6
6847152-4/9/2023 1:06:00 PM68471524/9/2023 1:06:00 PM125.6

Trying to count the loss and gain columns which all values come from this measure because the date is selected by the user

Diff30 =



VAR First30W =

    CALCULATE(
        MIN(AllWeights[Date]),
        FILTER(
            AllWeights,
            AllWeights[Date] >= [sDateLess30] &&
            AllWeights[Date] <= [selectDate] &&
            AllWeights[ClientId] = SELECTEDVALUE(AllWeights[ClientId])
        )
    )

VAR FirstValue =
    CALCULATE(
        MIN(AllWeights[Value]),
        FILTER(
            AllWeights,
            AllWeights[ManPK] = MINX(
                FILTER(
                    AllWeights,
                    AllWeights[Date] = First30W &&
                    AllWeights[ClientId] = SELECTEDVALUE(AllWeights[ClientId])
                ),
                AllWeights[ManPK]
            )
        )
    )





VAR Last30W =
    CALCULATE(
        MAX(AllWeights[Date]),
        FILTER(
            AllWeights,
            AllWeights[Date] >= [sDateLess30] &&
            AllWeights[Date] <= [selectDate] &&
            AllWeights[ClientId] = SELECTEDVALUE(AllWeights[ClientId])
        )
    )

VAR LastValue =
    CALCULATE(
        MAX(AllWeights[Value]),
        FILTER(
            AllWeights,
            AllWeights[ManPK] = MAXX(
                FILTER(
                    AllWeights,
                    AllWeights[Date] = Last30W &&
                    AllWeights[ClientId] = SELECTEDVALUE(AllWeights[ClientId])
                ),
                AllWeights[ManPK]
            )
        )
    )








Var CompareFisrtToLast = IF(LastValue <> FirstValue,DIVIDE((LastValue-FirstValue),FirstValue),BLANK())

Var Diff = If(ISBLANK(FirstValue),BLANK(),CompareFisrtToLast)



RETURN

Diff
-----------------------------------
Loss02% = If([Diff30] <= -.002,1,"")

------------------------------------------

Gain02% = If([Diff30] >= .002,1,"")

nabullock_0-1683647733461.png

 

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.

Top Solution Authors