Power BI couting - powerbi

I'm trying to create a measure that will count values from the table below. How can I count projects that have at least one task and date and how can I count projects that have two tasks and dates?
Bonus question: how can I count projects that have at least one task and no date (null) and how can I count projects with two tasks done and no dates?

Here below 4 measures is for you-
1.
one_one =
var count_task_1 = IF(min(project_count[task 1]) <> BLANK() && MIN(project_count[date 1]) <> BLANK(),1,0)
var count_task_2 = IF(min(project_count[task 2]) <> BLANK() && MIN(project_count[date 2]) <> BLANK(),1,0)
var count_task_3 = IF(min(project_count[task 3]) <> BLANK() && MIN(project_count[date 3]) <> BLANK(),1,0)
RETURN
IF(
(count_task_1+count_task_2+count_task_3) >= 1,
1,
0
)
2.
two_two =
var count_task_1 = IF(min(project_count[task 1]) <> BLANK() && MIN(project_count[date 1]) <> BLANK(),1,0)
var count_task_2 = IF(min(project_count[task 2]) <> BLANK() && MIN(project_count[date 2]) <> BLANK(),1,0)
var count_task_3 = IF(min(project_count[task 3]) <> BLANK() && MIN(project_count[date 3]) <> BLANK(),1,0)
RETURN
IF(
(count_task_1+count_task_2+count_task_3) >= 2,
1,
0
)
3.
one_no_date =
var count_task_1 = IF(min(project_count[task 1]) <> BLANK() && MIN(project_count[date 1]) = BLANK(),1,0)
var count_task_2 = IF(min(project_count[task 2]) <> BLANK() && MIN(project_count[date 2]) = BLANK(),1,0)
var count_task_3 = IF(min(project_count[task 3]) <> BLANK() && MIN(project_count[date 3]) = BLANK(),1,0)
RETURN
IF(
(count_task_1+count_task_2+count_task_3) >= 1,
1,
0
)
4.
two_no_date =
var count_task_1 = IF(min(project_count[task 1]) <> BLANK() && MIN(project_count[date 1]) = BLANK(),1,0)
var count_task_2 = IF(min(project_count[task 2]) <> BLANK() && MIN(project_count[date 2]) = BLANK(),1,0)
var count_task_3 = IF(min(project_count[task 3]) <> BLANK() && MIN(project_count[date 3]) = BLANK(),1,0)
RETURN
IF(
(count_task_1+count_task_2+count_task_3) >= 2,
1,
0
)
Here is the output-
You can do your other necessary calculation using these logics

Related

I am getting a circular dependency error on power Bi when I put a calculation

KPI Value_3 Months =
VAR current_actual =
IF (ISBLANK ([Actual]), FALSE, TRUE)
VAR current_target =
IF (ISBLANK([Target]), FALSE, TRUE)
RETURN
IF(
current_target && current_target,
DIVIDE(CALCULATE(SUM(BI_SC_Perf_Measurement_Lvl2[Actual]),DATESINPERIOD(BI_SC_Perf_Measurement_Lvl2[Reporting_Period],LASTDATE(BI_SC_Perf_Measurement_Lvl2[Reporting_Period]),-3,MONTH))/3 ,
CALCULATE(SUM(BI_SC_Perf_Measurement_Lvl2[Target]),DATESINPERIOD(BI_SC_Perf_Measurement_Lvl2[Reporting_Period],LASTDATE(BI_SC_Perf_Measurement_Lvl2[Reporting_Period]),-3,MONTH))/3),
BLANK ()
)
and I am creating another column with the following code:
KPI Status_3 Months =
VAR _bottomthreshold2 = .55
VAR __middlethreshold2 = .75
VAR _topthreshold2 = 1
RETURN
SWITCH(
TRUE (),
[KPI Value_3 Months] < _bottomthreshold2, -1,
[KPI Value_3 Months] >= _bottomthreshold2
&& [KPI Value_3 Months] <= __middlethreshold2, 0,
[KPI Value_3 Months] > __middlethreshold2
&& [KPI Value_3 Months] < _topthreshold2, 1,
[KPI Value_3 Months] >= _topthreshold2, 2
)
I am getting this error "A circular dependency was detected: BI_SC_Perf_Measurement_Lvl2[KPI Value_3 Months], BI_SC_Perf_Measurement_Lvl2[KPI Color_3 Months], BI_SC_Perf_Measurement_Lvl2[KPI Status_3 Months], BI_SC_Perf_Measurement_Lvl2[KPI Value_3 Months]."

IF ELSE measures not returning 0

Good Day!
This is my code criteria, for the highlighted row, it will count ETD and ATD if there is value, but since there is none, it will return 0 and 0% for the calculation.
This is my measure,
CountNotBlank =
SUMX(
ADDCOLUMNS(
RawDatas,
"Count",
var Direction = RawDatas[Direction]
var Dep = RawDatas[Dep]
var res1 = COUNTROWS(
FILTER(
{RawDatas[ETD],RawDatas[ATD],RawDatas[ETA],RawDatas[ATA],RawDatas[Estimated Delivery],RawDatas[Actual Delivery]},
NOT ISBLANK([Value])))
var res2 = COUNTROWS(
FILTER(
{RawDatas[ETA],RawDatas[ATA],RawDatas[Estimated Delivery],RawDatas[Actual Delivery]},
NOT ISBLANK([Value])) )
var res3 = COUNTROWS(
filter(
{RawDatas[ETD] , RawDatas[ATD]},
NOT ISBLANK([Value]) ))
var res4 = COUNTROWS(
FILTER(
{RawDatas[ETA],RawDatas[ATA]},
NOT ISBLANK([Value])))
return
if (Direction = "Export" && LEFT(Dep, 1) = "D", res2 ,
if (Direction = "Export" && NOT(LEFT(Dep, 1) = "D") , res1,
if (Direction = "Import" , res3,
if (Direction = "Domestic" , res4,
0))))),
[Count])
I tried returning 0 if a condition isn't met, but it doesn't seem to work. Is there anything I missed?
Expectation
Any help will greatly appreciated.
Attached with the pbix: https://drive.google.com/file/d/1aHV6qz66yPMbqR34EdCEGd3UPK_lsStv/view?usp=sharing
I was able to produce your expected result by nesting the whole expression inside IF(ISBLANK(...:
CountNotBlank =
VAR notblankvar =
//your code from above not pasted here for readability//
RETURN IF(ISBLANK(notblankvar),0,notblankvar)
Let me know if it would be helpful to see my .pbix file.

Else If - Google Script

this script was working before on my Google Sheet, then all of a sudden, it stopped working. I notice that the first argument (if) is working, but all the codes after that is not working. Any ideas?
function onEdit(event) {
// assumes source data in sheet named Sheet1
// target sheet of move to named Sheet2
// test column with yes is col 7 or G
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Under Contract Response Form" && r.getColumn() == 7 && (r.getValue() == "Closed" || r.getValue() == "Expired" || r.getValue() == "Cancelled")) {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Closed/Expired & Cancelled");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).copyTo(target);
s.deleteRow(row);
} else if(s.getName() == "Listing Response Form" && r.getColumn() == 7 && r.getValue() == "Pending" ) {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Under Contract Response Form");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).copyTo(target);
s.deleteRow(row);
} else if(s.getName() == "Listing Response Form" && r.getColumn() == 7 && r.getValue() == "Cancelled" ) {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Closed/Expired & Cancelled");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).copyTo(target);
s.deleteRow(row);
} else if(s.getName() == "Under Contract Response Form" && r.getColumn() == 7 && (r.getValue() == "Pre-list" || r.getValue() == "Withheld" || r.getValue() == "Coming Soon" || r.getValue() == "Active")) {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Listing Response Form");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).copyTo(target);
s.deleteRow(row);
} else if(s.getName() == "Closed/Expired & Cancelled" && r.getColumn() == 7 && r.getValue() == "Pending" ) {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Under Contract Response Form");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).copyTo(target);
s.deleteRow(row);
}
}
The script looks fine, so chances are that one or more sheets has been renamed, or columns inserted or deleted. Check the sheet names and look for things like leading or trailing spaces. Also ensure that the values that should trigger row move appear in column G.
You can make row moves more robust by using column names instead of column numbers. See the moveRowsFromSpreadsheetToSpreadsheet_ script.

Create column "after" in Powerbi (DAX)

I have the following information and I want to create the column "Later" From isProm : is the next day have the same value or no?
Date isProm Later
2018-06-06 1 1
2018-06-13 1 1
2018-08-20 1 1
2018-09-12 1 0
2018-09-12 0 0
Could you help me to do that with day please?
Thank you very much,
Ana
Create your new Custom Column with this below code-
Option 1:
later =
var current_row_isporm = your_table_name[isProm]
var current_row_date = your_table_name[Date]
var next_date =
CALCULATE(
MIN(your_table_name[Date]),
FILTER(
ALL(your_table_name),
your_table_name[Date] > current_row_date
)
)
var nex_date_isporm =
CALCULATE(
MIN(your_table_name[isProm]),
FILTER(
ALL(your_table_name),
your_table_name[Date] = next_date
)
)
RETURN IF(current_row_isporm = nex_date_isporm,1,0)
Option 2: You can also use this below code for same output-
later =
var current_row_isporm = your_table_name[isProm]
var current_row_date = your_table_name[Date]
var next_date_isporm =
CALCULATE(
MINX(
TOPN(
1,
FILTER(
ALL(your_table_name),
your_table_name[Date] > current_row_date
),
your_table_name[Date].[Date],ASC
),
your_table_name[isProm]
)
)
RETURN IF(current_row_isporm = next_date_isporm,1,0)
Here is the output. I have slightly different output because of date format in my laptop.

Current Fiscal Week with ISO Calendar

I have implemented a fiscal calendar into my Power BI Data Model for some time intelligence magic.
This fiscal calendar has a specific start and end date for each month and is mainly based on ISO 8601 Calendar (Gregorian).
However, my current approach is not working anymore for this year, since the filter "Current Fiscal Week" is not working. If I filter on Current Fiscal Week, then I get the second week of January instead of the first week.
But why?
My code has the following structure:
Calendar =
VAR BaseCalendar =
CALENDAR (
DATE ( 2020, 1, 1 ),
DATE ( 2022, 01, 03 )
)
RETURN
GENERATE (
BaseCalendar,
VAR BaseDate = [Date]
VAR WeekNumber =
WEEKNUM ( BaseDate )
VAR Year =
YEAR ( BaseDate )
VAR FiscalWeek =
WEEKNUM (
BaseDate,
21
)
VAR FiscalYear =
IF (
FiscalWeek < 5
&& WeekNumber > 50,
Year + 1,
IF (
FiscalWeek > 50
&& WeekNumber < 5,
Year - 1,
Year
)
)
RETURN
ROW (
"Fiscal Week", FiscalWeek,
"Current Fiscal Week",
IF (
AND (
FiscalWeek
= WEEKNUM (
TODAY (),
2
),
FiscalYear
= YEAR (
TODAY ()
)
),
TRUE (),
FALSE ()
)
)
)
I think that the Current Fiscal week should be found with the same formulas used to compute the FiscalWeek and FiscalYear. I put the variable definitions for the new variables outside of the GENERATE, since they just depend on TODAY()
VAR TodayBaseDate =
TODAY()
VAR TodayWeekNumber =
WEEKNUM( TodayBaseDate )
VAR TodayYear =
YEAR( TodayBaseDate )
VAR TodayFiscalWeek =
WEEKNUM( TodayBaseDate, 21 )
VAR TodayFiscalYear =
IF(
TodayFiscalWeek < 5
&& TodayWeekNumber > 50,
TodayYear + 1,
IF( TodayFiscalWeek > 50 && TodayWeekNumber < 5, TodayYear - 1, TodayYear )
)
VAR BaseCalendar =
CALENDAR( DATE( 2020, 1, 1 ), DATE( 2022, 01, 03 ) )
RETURN
GENERATE(
BaseCalendar,
VAR BaseDate = [Date]
VAR WeekNumber =
WEEKNUM( BaseDate )
VAR Year =
YEAR( BaseDate )
VAR FiscalWeek =
WEEKNUM( BaseDate, 21 )
VAR FiscalYear =
IF(
FiscalWeek < 5
&& WeekNumber > 50,
Year + 1,
IF( FiscalWeek > 50 && WeekNumber < 5, Year - 1, Year )
)
RETURN
ROW(
"Week day", FORMAT( [Date], "ddd" ),
"Today", TODAY(),
"Fiscal Week", FiscalWeek,
"Current Fiscal Week",
AND( FiscalWeek = TodayFiscalWeek, FiscalYear = TodayFiscalYear )
)
)